03 Query Docs
Filter, sort, project — ZMongo 03 Query Docs
- session
- json
- ids
- indexed
03 List Docs is the friendly "show me some rows" node. 03 Query Docs is the one you reach for when "some rows" isn't good enough - when you need a filter, a sort order, a projection, or the ability to fetch one specific document versus many. It's the most powerful read node in ComfyUI-ZMongo's document suite, and it's where the database actually starts earning its keep.
Think of the use cases: "give me the 20 most recently updated prompt documents for this project", "find the image document that was generated yesterday", "get just the metadata field, not the whole record". List Docs can't do those; Query Docs can, because it exposes the Mongo-style machinery under the hood.
How it works
The node passes your JSON inputs through to session.query_docs():
query_json- the filter, MongoDB-style.{}is "match everything",{"project_name": "default"}narrows to a project. You can use operators like{"created_at": {"$gte": "2026-08-01"}}.many- boolean, defaulttrue.truereturns a list of matching docs;falsetreats it as a single-document fetch (and you'd typically also set adocument_id).projection_json- which fields to include/exclude.{}means full documents.{"metadata": 1}returns only the metadata key. This is your bandwidth control for big records.sort_json- a JSON array of[field, direction]pairs, e.g.[["updated_at", -1]]for newest first. Default[]means natural order.document_id,limit,skip,cache- the same story as the rest of the pack.limitcaps at 500.
Outputs: json (full response), ids (list of matching document IDs), indexed ("0: id" preview text). Like List Docs, failures show up as an error payload in json plus empty lists rather than a crash.
The inputs and outputs that matter
For a beginner, session, collection_name, and query_json are the trio that matters; the rest have sane defaults. many: true + limit is the standard "recent N docs" recipe, and projection_json is the trick that keeps queries fast when documents carry embedded images. The ids output feeds straight into 99 Select Nth Item or 03 Get Doc.
Install
Same as every ZMongo node:
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. No model downloads.
Troubleshooting
- Error in
jsonimmediately - almost always malformedquery_json,projection_json, orsort_json. Remember:query_jsonandprojection_jsonmust be JSON objects ({}), whilesort_jsonmust be a JSON array ([]). Mixing those up is the #1 footgun. - Query returns nothing when you know data exists - field names in the filter must match the keys actually stored. ZMongo docs often nest project-scoped data, so check with
04 Metadata Flattened Pathsto see the real key paths before filtering on them. many: falsewith a blankdocument_id- you asked for one document but didn't say which. Either set the ID or flipmanyback to true.- Slow queries - add a projection to drop image/binary fields you don't need, and raise
limitinstead of looping.
Query Docs is the node that turns ZMongo from "a weird place to save JSON" into an actual searchable parameter library.
Inputs (11)
| Name | Type | Default | Description |
|---|---|---|---|
| session | ZMONGO_API_SESSION | — | |
| collection_name | STRING | — | |
| query_json | STRING | {} | — |
| document_id | STRING | — | |
| many | BOOLEAN | true | — |
| limit | INT | 501–500 | — |
| skip | INT | 00–1000000 | — |
| projection_json | STRING | {} | — |
| sort_json | STRING | [] | — |
| cache | BOOLEAN | false | — |
| refresh_tokenopt | STRING | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| json | STRING | — |
| ids | * | — |
| indexed | STRING | — |