Nodes/ComfyUI-ZMongo/99 Select Nth Item
ComfyUI Node

99 Select Nth Item

Pick items out of any list with one expression — ZMongo 99 Select Nth Item

By CentralFloridaAttorney·Created 5 months ago·Updated 2 months ago· 1
99 Select Nth Item
  • items_list
  • item
  • status
  • selected_items
  • selected_json
  • indexed_selected_items
  • count
index0
fallback
selection
modeauto
include_endtrue
dedupetrue

99 Select Nth Item is the pack's Swiss-army list slicer. It takes any list - the ids output from 03 List Docs, a list of prompt variants, whatever - and pulls out exactly the items you want using a compact expression syntax. It's a pure utility node: no database, no session, just "here's a list, here's what to select."

It exists because the rest of the pack is constantly producing lists, and you're constantly wanting one specific element. ids from a query is a list of a hundred document IDs; you want #3, or the last one, or a range, or every third. This node is the bridge.

The selection syntax (the thing to learn)

The selection input understands a small mini-language (from the author's own tooltip):

  • 3 - just index 3.
  • 2-7 - inclusive range 2 through 7 (respects include_end).
  • 7-2 - the same range backwards.
  • 0,2,5 - a custom set.
  • 0,2-5,9 - mixed indexes and ranges.
  • * or all - everything.
  • first, last, -1 - handy aliases (negative indexes count from the end).

Leave selection empty and it falls back to the index input. The mode input (auto / single / range / series / all) lets you force how the expression is interpreted; auto guesses, and you only need to touch it when an ambiguous expression needs disambiguating. dedupe (default true) removes repeated indexes so 0,0,0 doesn't multiply the output.

How it works

It parses your expression, normalizes each index (negative → "from the end", clamped to the list), and emits:

  • item - the first selected item, as a string. The convenient single-value output.
  • selected_items - the full list of selected items.
  • selected_json - the selection serialized as JSON.
  • indexed_selected_items - "0: value" preview text.
  • status - a message describing what happened (including warnings about ignored invalid indexes).
  • count - how many were selected.

If the list is empty or the index is out of range, you get fallback in item and a sensible empty result rather than a crash.

Install

Standard pack install:

cd ComfyUI/custom_nodes
git clone https://github.com/CentralFloridaAttorney/ComfyUI-ZMongo
cd ComfyUI-ZMongo
pip install -r requirements.txt

or ComfyUI Manager → "ComfyUI-ZMongo" → restart.

Troubleshooting

  • Wrong item coming out - check include_end. It defaults to true, so 2-7 includes 7. If you wanted exclusive, flip it.
  • item is empty but the list has items - either the index is out of range or the selection expression didn't parse. The status output tells you what was ignored; read it instead of guessing.
  • Duplicates in selected_items - dedupe is off. Turn it on, or be deliberate about wanting repeats.
  • fallback returning when you expected something - remember the fallback also fires on an empty list, not just a bad index.

Select Nth Item won't change your life by itself, but it's the glue that turns the pack's lists into actual usable values - and it's the cleanest way to feed one doc ID at a time into 03 Get Doc.

CategoryZMongo/99 Helpers

Inputs (7)

NameTypeDefaultDescription
items_list*
indexINT0-1000000–1000000
fallbackSTRING
selectionSTRINGExamples: 0, 2-7, 7-2, 0,2,5, 0,2-5,9, *, all, first, last, -1. Empty uses index.
modeCOMBOauto5 options: auto, single, range, series, all
include_endBOOLEANtrue
dedupeBOOLEANtrue

Outputs (6)

NameTypeDescription
itemSTRING
statusSTRING
selected_items*
selected_jsonSTRING
indexed_selected_itemsSTRING
countINT