All nodes/Data/Database
DB Count
Counts the number of documents matching the filter.
Type in the graph: db_count
Exec
An error branch can be enabled (expose_error_output) to handle failures on their own path.
Ports can be split into separate execution and data handles.
Try it
Minimal working workflow
- Execute + Data
Runs as pasted
When to use it
Count answers “how many” without carrying the documents out: how many tickets are open, whether a
record with this key already exists, whether a per-customer limit is exceeded. It is cheaper than
db_find followed by measuring the array and — more importantly — more honest:
Find’s count is the size of the returned page, cut down by the limit, while here every match is
counted. When you need the document itself after the check, go straight to
db_find_one: it has a found field, and that is one query instead of two.
How it works
The Filter port carries both the trigger and the filter; an object arriving over the edge replaces
the configured filter, an empty trigger keeps it, and a value of another shape fails the node —
otherwise a typo would quietly become “count the whole collection”. The output holds a single field,
count.
An empty filter is allowed here and means “every document in the collection”; the store answers that
with one fast query. A filter with operators ($gt, $in, $regex) is evaluated over the candidate
documents, so on large collections keep at least one exact match on a top-level field in it.
Common mistakes
- Counting through Find.
counton db_find is the page size: with a limit of 100 the “total” will never exceed a hundred. - Counting in order to read. Two nodes are two trips to the database, and the data can change in between. For “is it there, and which one” db_find_one is enough.
- Building a limit on a count. “Count, then insert if fewer than ten” is not a guard: a parallel run can insert between the two nodes. Rules like that must rest on a unique key and an upsert (db_update), not on a counter.
- Templates in the filter field.
{{ … }}is not expanded in a JSON editor — build a dynamic filter with a template or code_javascript and feed it to the port. - Comparing the number inside a template. A branch is easier with if on
{{ nodes.<id>.output.count }}than by assembling text around the number and parsing it downstream.
Inputs
| Port | Wire | Payload | Notes |
|---|---|---|---|
Filterinput | Execute + Dataexecute_data | — | Run trigger and dynamic payload (overrides static config). The payload must be an object — a value of any other shape fails the node instead of being ignored. |
Outputs
| Port | Wire | Payload | Notes |
|---|---|---|---|
Resultoutput | Execute + Dataexecute_data | object |
Configuration
| Field | Type | Default | Description |
|---|---|---|---|
Collectioncollection_id | string | "" | Collection ID |
Filterfilter | object | — |
Shared fields
Every node has these three — the platform adds them, not the node author.
expose_error_output— When enabled, show an execution output to connect nodes that run if this step fails.split_ports_in— Show separate execution and data input handles instead of one combined port.split_ports_out— Show separate execution and data output handles instead of one combined port.