QANode Logo

MongoDB Node

The MongoDB node allows you to perform operations on a MongoDB database, including queries, insertions, updates, deletions, and aggregation pipelines.


Overview

PropertyValue
Typemongodb-query
CategoryDatabase
Color🟢 Green (#22c55e)
Inputin
Outputout

Connection

Using Saved Credentials (Recommended)

Select a credential of type MongoDB.

Manual Configuration

FieldTypeDescription
URIstringMongoDB connection string
DatabasestringDatabase name
CollectionstringCollection name

Example URIs:

mongodb://user:password@host:27017/database?authSource=admin
mongodb+srv://user:password@cluster.example.mongodb.net/database

Operations

find

Finds multiple documents.

FieldTypeDescription
FilterJSONSearch criteria
LimitnumberMaximum number of documents (default: 20)
OptionsJSONProjection, sort, etc.

Example:

// Filter
{ "active": true, "age": { "$gte": 18 } }

// Options
{ "sort": { "name": 1 }, "projection": { "name": 1, "email": 1 } }

findOne

Finds a single document.

FieldTypeDescription
FilterJSONSearch criteria

Example:

{ "_id": "abc123" }
{ "email": "john@example.com" }

insertOne

Inserts a new document.

FieldTypeDescription
DocumentJSONDocument to be inserted

Example:

{
  "name": "John",
  "email": "john@example.com",
  "createdAt": "{{ new Date().toISOString() }}"
}

updateOne

Updates an existing document.

FieldTypeDescription
FilterJSONCriteria to find the document
UpdateJSONUpdate operations

Example:

// Filter
{ "_id": "abc123" }

// Update
{ "$set": { "active": false, "updatedAt": "2024-01-01" } }

deleteOne

Removes a document.

FieldTypeDescription
FilterJSONCriteria to find the document

Example:

{ "email": "remove@example.com" }

aggregate

Executes an aggregation pipeline.

FieldTypeDescription
PipelineJSONArray of stages
LimitnumberMaximum number of results

Example:

[
  { "$match": { "status": "active" } },
  { "$group": { "_id": "$department", "count": { "$sum": 1 } } },
  { "$sort": { "count": -1 } }
]

Outputs

OutputTypeDescription
documentsarrayReturned documents (find, aggregate)
documentanySingle document (findOne)
resultobjectOperation result (insert, update, delete)

Accessing Outputs

// List of documents
{{ steps.mongo.outputs.documents }}

// First document
{{ steps.mongo.outputs.documents[0].name }}

// Single document
{{ steps.mongo.outputs.document.email }}

// Insert result
{{ steps.mongo.outputs.result.insertedId }}

// Update result
{{ steps.mongo.outputs.result.modifiedCount }}

Practical Examples

Verify data after API call

[HTTP Request: POST /api/products]
    │
    â–¼
[MongoDB: findOne → { "sku": "{{ steps.api.outputs.json.sku }}" }]
    │
    â–¼
[If: {{ steps.mongo.outputs.document }} !== null]
    │ true → [Log: "Product created: {{ steps.mongo.outputs.document.name }}"]

Prepare test data

[MongoDB: insertOne → { "name": "Test User", "role": "tester" }]
    │
    â–¼
[HTTP Request: GET /api/users/{{ steps.insert.outputs.result.insertedId }}]

Report with aggregation

[MongoDB: aggregate → [
    { "$match": { "date": { "$gte": "2024-01-01" } } },
    { "$group": { "_id": "$status", "count": { "$sum": 1 } } }
]]
    │
    â–¼
[Log: "Results: {{ JSON.stringify(steps.aggregate.outputs.documents) }}"]

Tips

  • The Filter field accepts all MongoDB operators ($eq, $ne, $gt, $in, $regex, etc.)
  • Use {{ }} expressions in JSON values to inject dynamic data
  • The default limit of 20 documents can be changed to avoid returning excessive data
  • For complex operations, use aggregation pipelines
  • Test the connection on the credentials screen before using it in the flow