Skip to main content

DB::MONGO

Perform Mongo queries.

Prerequisite

Syntax

actions:
<action-id>:
type: DB::MONGO
props:
queryType: <query_type>
document: <document>
collection: <collection_name>

Properties

PropertyDescriptionType
<action-id>Unique identifier for the actionstring
typeType of the actionstring
propsProperties specific to this action. Refer to props section for more details.object

props

PropertyDescriptionTypeRequired
queryMongoDB queryobjecttrue
queryTypeThe type of MongoDB query. See the queryType section for more detailsstringtrue
documentThe document to be inserted or updated in MongoDBobject
collectionThe MongoDB collection in which to perform the querystringtrue

queryType

PropertyDescription
INSERTInserts a new document into the specified MongoDB collection
SAVEUpdates an existing document in the specified MongoDB collection
FINDRetrieves documents from the specified MongoDB collection based on a query
REMOVE_ALLDeletes all documents from the specified MongoDB collection

Output

📝 Note: Can be accessed using context["last_output"]

KeyDescriptionType
resultOutcome of the query, either an _id, a removed_count, or a list of documents. Refer to result section.object or array
timeTakenTime taken, in millisecondslong
errorError message, if any, produced while executing the querystring

result

PropertyDescriptionType
INSERTReturns the _id of the inserted documentobject
SAVEReturns the _id of the updated document or null on failureobject
FINDReturns a list of documents foundarray
REMOVE_ALLReturns the number of removed documents as removed_countobject
{ "result": { "_id": "63c1fe90f1582d72983caf6f" } }
{ "result": { "_id": "63c1fe90f1582d72983caf6f" } }
{
"result": [
{ "_id": "63c1fe90f1582d72983caf6f", "name": "John" },
{ "_id": "94c1fe90f1582d72983caf6c", "name": "Sarah" }
]
}
{ "result": { "removed_count": 1 } }

Example

mongoDbTests.yml
actions:
insert:
type: DB::MONGO
props:
queryType: INSERT
document: { "name": "John" }
collection: users
save:
type: DB::MONGO
props:
query: { "_id": "63c1fe90f1582d72983caf6f", "name": "John Jr" }
queryType: SAVE
collection: users
find:
type: DB::MONGO
props:
query: { "name": "John Jr" }
queryType: FIND
collection: users
remove:
type: DB::MONGO
props:
query: { "name": "John" }
queryType: REMOVE_ALL
collection: users

tests:
mongodbTest:
tasks:
- resource: resources.mongodb
action: actions.insert
- resource: resources.mongodb
action: actions.save
- resource: resources.mongodb
action: actions.find
- resource: resources.mongodb
action: actions.remove