Nodes/ComfyUI-ZMongo/06 Select Nth Document Item
ComfyUI Node

06 Select Nth Document Item

The safest way to grab one item out of a list

By CentralFloridaAttorney·Created 5 months ago·Updated 2 months ago· 1
06 Select Nth Document Item
  • items_list
  • item
  • document_id_link
  • field_path_link
  • file_path_link
  • filename_link
  • text_link
  • status
index0
fallback
semantic_hintauto

A list output on its own is useless until you pick one element out of it. "06 Select Nth Document Item" is that picker: feed it the list (say, the document_ids output from "06 List Documents") and an index, and it returns the item at that position as a plain string. Simple as that. But there's a surprisingly careful bit of engineering underneath, and it's the reason you should use this node instead of a generic list-index node.

How it works

The items_list input takes a ComfyUI list (it's marked INPUT_IS_LIST, so the node handles batch/list wiring for you), and index (default 0) picks the position - clamped into range rather than erroring, and the fallback string covers the empty-list case. Out pops item as a STRING, plus a status string describing what got selected (Selected 3/12: ...).

The clever part is the semantic_hint selector (auto, document_id, field_path, file_path, filename, text). Because a list of document IDs and a list of filenames both look like "a list of strings," the node can't know what it's handling - so the hint controls the guarded semantic outputs: document_id_link, field_path_link, file_path_link, filename_link, text_link. Those typed link outputs are how this pack prevents you from wiring a filename into a document-ID socket and getting silent misses. In auto mode it sniffs the value shape; in explicit mode it only fills the matching output. The one you'll actually use downstream is almost always document_id_link, fed into "06 Get Document" or "06 Get Document Text".

Install

cd ComfyUI/custom_nodes
git clone https://github.com/CentralFloridaAttorney/ComfyUI-ZMongo

Restart, or install "ComfyUI-ZMongo" via ComfyUI Manager.

Where people get burned

Indexing starts at zero, not one. index 0 is the first item, and the status output tells you which one you actually got (Selected 1/12) - glance at it once when you set up the workflow and you'll avoid the off-by-one that bites everyone at least once.

Second, fallback only kicks in for an empty list or a fully out-of-range pick; with clamping on, an out-of-range index just snaps to the nearest valid item rather than erroring. That's friendly but it means you can silently get item 0 when you meant item 12. If exact selection matters, read status.

Last: semantic_hint set to auto on a list that could be either IDs or filenames might route the link output the wrong way. If your downstream "Get Document" node says "not found," set the hint explicitly to document_id - the cost is one dropdown, the payoff is not debugging a phantom database problem.

CategoryZMongo/03 Documents

Inputs (4)

NameTypeDefaultDescription
items_list*
indexINT00–1000000
fallbackSTRING
semantic_hintCOMBOauto6 options: auto, document_id, field_path, file_path, filename, text

Outputs (7)

NameTypeDescription
itemSTRING
document_id_linkZMONGO_DOCUMENT_ID
field_path_linkZMONGO_FIELD_PATH
file_path_linkZMONGO_FILE_PATH
filename_linkZMONGO_FILENAME
text_linkZMONGO_TEXT
statusSTRING