99 Select Nth Item
Pick items out of any list with one expression — ZMongo 99 Select Nth Item
- items_list
- item
- status
- selected_items
- selected_json
- indexed_selected_items
- count
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 (respectsinclude_end).7-2- the same range backwards.0,2,5- a custom set.0,2-5,9- mixed indexes and ranges.*orall- 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 totrue, so2-7includes 7. If you wanted exclusive, flip it. itemis empty but the list has items - either the index is out of range or the selection expression didn't parse. Thestatusoutput tells you what was ignored; read it instead of guessing.- Duplicates in
selected_items-dedupeis off. Turn it on, or be deliberate about wanting repeats. fallbackreturning 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.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| items_list | * | — | |
| index | INT | 0-1000000–1000000 | — |
| fallback | STRING | — | |
| selection | STRING | Examples: 0, 2-7, 7-2, 0,2,5, 0,2-5,9, *, all, first, last, -1. Empty uses index. | |
| mode | COMBO | auto | 5 options: auto, single, range, series, all |
| include_end | BOOLEAN | true | — |
| dedupe | BOOLEAN | true | — |
Outputs (6)
| Name | Type | Description |
|---|---|---|
| item | STRING | — |
| status | STRING | — |
| selected_items | * | — |
| selected_json | STRING | — |
| indexed_selected_items | STRING | — |
| count | INT | — |