Skip to main content

MongoDB

Add Query

You can add a query step by adding a workflow from the page list.
When you select the MongoDB data source from the workflow step sidebar, the query input window appears.
The method to add a data source is described in the MongoDB data source guide.

mongodb

Actions

find (Retrieve)

Retrieves documents from a collection.

mongodb

Parameters

NameTypeDescription
Collection (collection)stringCollection name
Filter (filter)objectQuery condition
Limit (limit)numberLimit the number of documents to return
Skip (skip)numberSkip the number of documents
Sort (sort)objectSort condition

Query Result

Returns an array of documents retrieved.

[
{ "_id": "507f1f77bcf86cd799439011", "name": "John", "age": 30 },
{ "_id": "507f1f77bcf86cd799439012", "name": "Jane", "age": 25 }
]

insertOne (Insert a single document)

Inserts a single document into a collection.

mongodb

Parameters

NameTypeDescription
Collection (collection)stringCollection name
Document (document)objectDocument data to insert
Options (options)objectInsert options

Query Result

When executing the insertOne action, it returns the ID of the inserted document in the following structure. For more details, please refer to the MongoDB official documentation.

{
"acknowledged": true,
"insertedId": "507f1f77bcf86cd799439011"
}

insertMany (Insert multiple documents)

Inserts multiple documents into a collection at once.

mongodb

Parameters

NameTypeDescription
Collection (collection)stringCollection name
Documents (documents)arrayDocuments to insert
Options (options)objectInsert options

Query Result

When executing the insertMany action, it returns the IDs of the inserted documents in the following structure. For more details, please refer to the MongoDB official documentation.

{
"acknowledged": true,
"insertedIds": ["507f1f77bcf86cd799439011", "507f1f77bcf86cd799439012"]
}

replaceOne (Replace a document)

Replaces a single document that matches the filter condition with a new document.

mongodb

Parameters

NameTypeDescription
Collection (collection)stringCollection name
Filter (filter)objectFilter condition
Replacement (replacement)objectNew document to replace
Options (options)objectReplace options

Query Result

When executing the replaceOne action, it returns the number of documents replaced in the following structure. For more details, please refer to the MongoDB official documentation.

{
"acknowledged": true,
"matchedCount": 1,
"modifiedCount": 1
}

updateOne (Update a single document)

Updates a single document that matches the filter condition.

mongodb

Parameters

NameTypeDescription
Collection (collection)stringCollection name
Filter (filter)objectFilter condition
Update (update)objectUpdate content
Options (options)objectUpdate options

Query Result

When executing the updateOne action, it returns the number of documents modified in the following structure. For more details, please refer to the MongoDB official documentation.

{
"acknowledged": true,
"matchedCount": 1,
"modifiedCount": 1
}

updateMany (Update multiple documents)

Updates all documents that match the filter condition.

mongodb

Parameters

NameTypeDescription
Collection (collection)stringCollection name
Filter (filter)objectFilter condition
Updates (updates)arrayUpdate content
Options (options)objectUpdate options

Query Result

When executing the updateMany action, it returns the number of documents modified in the following structure. For more details, please refer to the MongoDB official documentation.

{
"acknowledged": true,
"matchedCount": 5,
"modifiedCount": 5
}

deleteOne (Delete a single document)

Deletes a single document that matches the filter condition.

mongodb

Parameters

NameTypeDescription
Collection (collection)stringCollection name
Filter (filter)objectDelete condition
Options (options)objectDelete options

Query Result

When executing the deleteOne action, it returns the number of documents deleted in the following structure. For more details, please refer to the MongoDB official documentation.

{
"acknowledged": true,
"deletedCount": 1
}

deleteMany (Delete multiple documents)

Deletes all documents that match the filter condition.

mongodb

Parameters

NameTypeDescription
Collection (collection)stringCollection name
Filter (filter)objectFilter condition
Options (options)objectDelete options

Query Result

When executing the deleteMany action, it returns the number of documents deleted in the following structure. For more details, please refer to the MongoDB official documentation.

{
"acknowledged": true,
"deletedCount": 10
}

distinct (Get unique values)

Retrieves unique values for a specified field.

mongodb

Parameters

NameTypeDescription
Collection (collection)stringCollection name
Field Name (fieldName)stringField name to retrieve
Filter (filter)objectFilter condition

Query Result

When executing the distinct action, it returns an array of unique values in the following structure. For more details, please refer to the MongoDB official documentation.

["Seoul", "New York", "London", "Tokyo"]

count (Calculate the number of documents)

Calculates the number of documents that match the filter condition.

mongodb

Parameters

NameTypeDescription
Collection (collection)stringCollection name
Filter (filter)objectFilter condition
Options (options)objectCalculation options

Query Result

When executing the count action, it returns the number of documents in the following structure. For more details, please refer to the MongoDB official documentation.

{ "n": 42 }

aggregate (Aggregate)

Aggregates data for analysis.

mongodb

Parameters

NameTypeDescription
Collection (collection)stringCollection name
Pipeline (pipeline)arrayAggregation pipeline

Query Result

When executing the aggregate action, it returns an array of aggregation results in the following structure. For more details, please refer to the MongoDB official documentation.

[
{
"_id": "Seoul",
"totalPopulation": 9700000,
"avgAge": 35.6
},
{
"_id": "Tokyo",
"totalPopulation": 13960000,
"avgAge": 38.2
}
]

bulkWrite (Bulk Write)

Executes multiple operations at once.

mongodb

Parameters

NameTypeDescription
Collection (collection)stringCollection name
Requests (requests)objectList of operations to execute

Query Result

When executing the bulkWrite action, it returns the result of the executed operations in the following structure. For more details, please refer to the MongoDB official documentation.

{
"acknowledged": true,
"insertedCount": 2,
"matchedCount": 3,
"modifiedCount": 3,
"deletedCount": 1,
"upsertedCount": 0
}

runCommand (Run Command)

Executes a database command directly.

mongodb

Parameters

NameTypeDescription
Collection (collection)stringCollection name
Command (command)objectCommand to execute

Query Result

When executing the runCommand action, it returns the result of the executed command in the following structure. For more details, please refer to the MongoDB official documentation.

{
"ok": 1,
"n": 100,
"avgObjSize": 157,
"size": 15700
}