Nodes/ComfyUI-ZMongo/06 Document Index Selector
ComfyUI Node

06 Document Index Selector

Slice and dice a document list with one string of index math

By CentralFloridaAttorney·Created 5 months ago·Updated 2 months ago· 1
06 Document Index Selector
  • items_list
  • selected_items
  • document_id_links
  • first_item
  • first_document_id_link
  • first_field_path_link
  • first_file_path_link
  • first_filename_link
  • first_text_link
  • selected_json
  • indexed_selected_items
  • count
  • success
  • status
selection0
fallback
clamp_indexestrue
dedupetrue
semantic_hintdocument_id
refresh_token

Select Nth Item grabs one element; this is the version that grabs many. "06 Document Index Selector" takes a list and a little index expression and returns the subset you asked for - a single index, a range, a comma-separated set, or everything. It's the list-filtering workhorse for when you want to process documents 2–7, or just the ones at positions 0, 3, and 9, without any custom code.

How it works

The selection string is an index-expression compiler. The README's examples are the whole grammar:

3        → just index 3
2-7      → indices 2 through 7 inclusive
0,2,5    → that exact set
0,2-5,9  → mixed: 0, 2,3,4,5, and 9
* or all → the entire list

It parses that, applies it to items_list, and returns selected_items as a list plus selected_json (the JSON form), indexed_selected_items (numbered for reading), count, success, and status. The two toggles are worth knowing:

  • clamp_indexes (default true) - out-of-range indexes snap to the nearest valid item instead of being dropped
  • dedupe (default true) - duplicate selections collapse while preserving order

And like its single-item sibling, it has semantic_hint (default document_id) driving the guarded link outputs - document_id_links (a list of typed links), first_document_id_link, plus first_field_path_link / first_file_path_link / first_filename_link / first_text_link for whichever value type you're slicing. first_item gives you the first selected value as a plain string.

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

Spacing and syntax: 2 - 7 with spaces parses less reliably than 2-7, and the docs' canonical examples are unspaced. Keep your expressions tight and you won't have to debug them. Also, ranges are inclusive - 2-7 is six items, not five. If you're coming from Python slicing where [2:7] excludes 7, unlearn that here.

The other trap is what's in the list. This selector doesn't care whether items_list holds IDs, filenames, or paths - it just slices strings. If you feed it filenames and then wire first_document_id_link into a Get node, you'll get a miss (the guarded links try to prevent exactly this, but only if the hint matches the data). Feed it document_ids from List Documents, set semantic_hint to document_id, and the intended loop - List → Index Selector → Get Text - works cleanly.

And a minor one: the fallback string covers the empty/no-match case, so you get a graceful empty result rather than a crash. That's friendly for automation, but it also means an empty selected_items is worth reading as a signal that your expression or list is wrong, not just "no results."

CategoryZMongo/03 Documents

Inputs (7)

NameTypeDefaultDescription
items_list*
selectionSTRING0Index expression: 0, 2-7, 0,2,5, 0,2-5,9, *, or all.
fallbackSTRINGReturned only when the input list is empty or no selection matches.
clamp_indexesBOOLEANtrueClamp out-of-range indexes to the nearest valid item instead of dropping them.
dedupeBOOLEANtrueRemove duplicate selected items while preserving order.
semantic_hintCOMBOdocument_idControls the guarded semantic link outputs.
refresh_tokenoptSTRING

Outputs (13)

NameTypeDescription
selected_items*
document_id_linksZMONGO_DOCUMENT_ID
first_itemSTRING
first_document_id_linkZMONGO_DOCUMENT_ID
first_field_path_linkZMONGO_FIELD_PATH
first_file_path_linkZMONGO_FILE_PATH
first_filename_linkZMONGO_FILENAME
first_text_linkZMONGO_TEXT
selected_jsonSTRING
indexed_selected_itemsSTRING
countINT
successBOOLEAN
statusSTRING