MongoDB

Send MongoDB queries with the MongoDB built-in.
Send an email to your configured MongoDB resource. The following MongoDB methods are available as built-ins.

Methods

find

FieldTypeDefaultDescription
resourcestringRequiredThe MongoDB resource.
collectionstringRequiredThe MongoDB collection.
filterobjectnullOptional filter criteria. Returns all documents if filter is not provided.
projectionobjectnullSpecify which fields to return in the results.
sortobjectnullSpecify the sort order of results.

findOne

FieldTypeDefaultDescription
resourcestringRequiredThe MongoDB resource.
collectionstringRequiredThe MongoDB collection.
filterobjectnullOptional filter criteria. Returns all documents if filter is not provided.
projectionobjectnullSpecify which fields to return in the results.
sortobjectnullSpecify the sort order of results.

updateOne

FieldTypeDefaultDescription
resourcestringRequiredThe MongoDB resource.
collectionstringRequiredThe MongoDB collection.
updateobjectRequiredThe documents to update.
filterobjectnullOptional filter criteria. Returns all documents if filter is not provided.
upsertbooleanfalseSpecifies whether to create a new document if one does not exist.

updateMany

FieldTypeDefaultDescription
resourcestringRequiredThe MongoDB resource.
collectionstringRequiredThe MongoDB collection.
updateobjectRequiredThe documents to update.
filterobjectnullOptional filter criteria. Returns all documents if filter is not provided.
upsertbooleanfalseSpecifies whether to create a new document if one does not exist.

findOneAndUpdate

FieldTypeDefaultDescription
resourcestringRequiredThe MongoDB resource.
collectionstringRequiredThe MongoDB collection.
updateobjectRequiredThe document to update.
filterobjectnullOptional filter criteria. Returns all documents if filter is not provided.
projectionobjectnullSpecify which fields to return in the results.
sortobjectnullSpecify the sort order of results.

findOneAndReplace

FieldTypeDefaultDescription
resourcestringRequiredThe MongoDB resource.
collectionstringRequiredThe MongoDB collection.
replacementobjectRequiredThe document to update.
filterobjectnullOptional filter criteria. Returns all documents if filter is not provided.
projectionobjectnullSpecify which fields to return in the results.
sortobjectnullSpecify the sort order of results.

insertOne

FieldTypeDefaultDescription
resourcestringRequiredThe MongoDB resource.
collectionstringRequiredThe MongoDB collection.
documentobjectRequiredThe document to insert.

insertMany

FieldTypeDefaultDescription
resourcestringRequiredThe MongoDB resource.
collectionstringRequiredThe MongoDB collection.
documents[]objectRequiredThe documents to insert.

findOneAndDelete

FieldTypeDefaultDescription
resourcestringRequiredThe MongoDB resource.
collectionstringRequiredThe MongoDB collection.
filterobjectnullOptional filter criteria. Returns all documents if filter is not provided.
projectionobjectnullSpecify which fields to return in the results.
sortobjectnullSpecify the sort order of results.

deleteOne

FieldTypeDefaultDescription
resourcestringRequiredThe MongoDB resource.
collectionstringRequiredThe MongoDB collection.
filterobjectnullOptional filter criteria. Returns all documents if filter is not provided.
projectionobjectnullSpecify which fields to return in the results.
sortobjectnullSpecify the sort order of results.

deleteMany

FieldTypeDefaultDescription
resourcestringRequiredThe MongoDB resource.
collectionstringRequiredThe MongoDB collection.
filterobjectnullOptional filter criteria. Returns all documents if filter is not provided.
projectionobjectnullSpecify which fields to return in the results.
sortobjectnullSpecify the sort order of results.

aggregate

FieldTypeDefaultDescription
resourcestringRequiredThe MongoDB resource.
collectionstringRequiredThe MongoDB collection.
pipeline[]objectRequiredSee aggregation-pipeline.

countDocuments

FieldTypeDefaultDescription
resourcestringRequiredThe MongoDB resource.
collectionstringRequiredThe MongoDB collection.
filterobjectRequiredCriteria to filter by.

distinct

FieldTypeDefaultDescription
resourcestringRequiredThe MongoDB resource.
fieldstringRequiredThe field to count.
collectionstringRequiredThe MongoDB collection.
filterobjectRequiredCriteria to filter by.

Usage Example

javascript
Copied
1
import airplane from "airplane";
2
3
export default airplane.task(
4
{
5
slug: "mongo_find_user",
6
resources: ["mongo_db"],
7
},
8
async (params) => {
9
const email = await airplane.mongodb.find(
10
"mongo_db", // The MongoDB resource.
11
"users", // The collection
12
{
13
filter: { name: "jane" },
14
limit: 2,
15
}
16
);
17
return email.output;
18
}
19
);