03 Count Docs
Knowing how much is in your store before you build around it
- session
- json
- count
03 Count Docs answers the most boring and most useful question in any data-backed workflow: how many documents are actually in there? It's a read-only node that returns a count for a collection, optionally filtered by a query.
Why bother? Because ZMongo's pitch is treating your store as a parameter library and asset hub, and every "loop over all my prompts" or "did the batch land?" workflow starts with a count. It's also a great cheap sanity check - fire it after a batch save and confirm the number grew, before you build a whole downstream pipeline on an assumption.
How it works
Required inputs:
session- from the API Key Session node.collection_name- the collection to count.query_json- a Mongo-style filter, defaults to{}(counts everything).document_id- count a single document by id if you like (the backend handles a targeted count).cache- boolean, default false. Turn it on if the count is expensive and you're polling repeatedly; just remember a cached count can be stale.
Outputs are lean:
json- the full backend payload (so you can see the raw response if the count looks wrong).count- the integer. The node digs through the response for a token/total/count key; if the backend shape changes,countfalls back to 0 rather than crashing.
Tips
- An optional
refresh_tokeninput exists - wire another node'srefreshoutput here to re-run the count when the store changes, and use thecountto drive loops or gates downstream. countis a genuine INT, so you can use it in math nodes or to decide whether to run a heavier node ("only summarize if we have documents").- A count of 0 with a
success: trueis normal - it means the collection is empty, not that it failed. Check thejsonoutput when in doubt; the node itself doesn't distinguish.
Install
ComfyUI Manager → search ComfyUI-ZMongo, or:
cd ComfyUI/custom_nodes
git clone https://github.com/CentralFloridaAttorney/ComfyUI-ZMongo
restart, and remember the pack's real dependency list is long even though this read-only node just needs the API session. First import after install takes a moment.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| session | ZMONGO_API_SESSION | — | |
| collection_name | STRING | — | |
| query_json | STRING | {} | — |
| document_id | STRING | — | |
| cache | BOOLEAN | false | — |
| refresh_tokenopt | STRING | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| json | STRING | — |
| count | INT | — |