MongoDB

Send MongoDB queries with the MongoDB built-in.
Airplane's MongoDB SDKs make it easy to issue one-off MongoDB requests from a task. To use this SDK, you'll need to configure a MongoDB resource.

Find

airplane.mongodb.find(mongodbResource, collection, opts)
mongodbResource
REQUIRED
string

Slug of MongoDB resource to use. See Resources

collection
REQUIRED
string

The MongoDB collection

opts.filter
optional
Default
null
object

Optional filter criteria. Returns all documents if filter is not provided.

opts.projection
optional
Default
null
object

Specify which fields to return in the results.

opts.sort
optional
Default
null
object

Specify the sort order of results.

opts.skip
optional
Default
null
number

How many results to skip.

opts.limit
optional
Default
null
number

How many results to reurn.

Returns
output
object[]

A list of MongoDB documents

Example
json
Copied
1
[{ "_id": "62c4caa466499db2981e496e", "fruit": "apple" }]

FindOne

airplane.mongodb.findOne(mongodbResource, collection, opts)
mongodbResource
REQUIRED
string

Slug of MongoDB resource to use. See Resources

collection
REQUIRED
string

The MongoDB collection

opts.filter
optional
Default
null
object

Optional filter criteria. Returns all documents if filter is not provided.

opts.projection
optional
Default
null
object

Specify which fields to return in the results.

opts.sort
optional
Default
null
object

Specify the sort order of results.

Returns
output
object

A MongoDB document. Empty if there were no results.

Example
json
Copied
1
{ "_id": "62c4caa466499db2981e496e", "fruit": "apple" }

UpdateOne

airplane.mongodb.updateOne(mongodbResource, collection, update, opts)
mongodbResource
REQUIRED
string

Slug of MongoDB resource to use. See Resources

collection
REQUIRED
string

The MongoDB collection

update
REQUIRED
object

The documents to update.

opts.filter
optional
Default
null
object

Optional filter criteria. Returns all documents if filter is not provided.

opts.upsert
optional
Default
false
boolean

Specifies whether to create a new document if one does not exist.

Returns
output.MatchedCount
number

The number of documents matching the filter.

output.ModifiedCount
number

The number of documents modified.

output.UpsertedCount
number

The number of documents upserted. 0 if upsert is false.

output.UpsertedID
string | null

The _id for the upserted document. null if upsert is false.

Example
json
Copied
1
{
2
"MatchedCount": 1,
3
"ModifiedCount": 1,
4
"UpsertedCount": 0,
5
"UpsertedID": null
6
}

UpdateMany

airplane.mongodb.updateMany(mongodbResource, collection, update, opts)
mongodbResource
REQUIRED
string

Slug of MongoDB resource to use. See Resources

collection
REQUIRED
string

The MongoDB collection

update
REQUIRED
object

The documents to update.

opts.filter
optional
Default
null
object

Optional filter criteria. Returns all documents if filter is not provided.

opts.upsert
optional
Default
false
boolean

Specifies whether to create a new document if one does not exist.

Returns
output.MatchedCount
number

The number of documents matching the filter.

output.ModifiedCount
number

The number of documents modified.

output.UpsertedCount
number

The number of documents upserted. 0 if upsert is false.

output.UpsertedID
string | null

The _id for the upserted document. null if upsert is false.

Example
json
Copied
1
{
2
"MatchedCount": 2,
3
"ModifiedCount": 2,
4
"UpsertedCount": 0,
5
"UpsertedID": null
6
}

FindOneAndUpdate

airplane.mongodb.findOneAndUpdate(mongodbResource, collection, update, opts)
mongodbResource
REQUIRED
string

Slug of MongoDB resource to use. See Resources

collection
REQUIRED
string

The MongoDB collection

update
REQUIRED
object

The documents to update.

opts.filter
optional
Default
null
object

Optional filter criteria. Returns all documents if filter is not provided.

opts.projection
optional
Default
null
object

Specify which fields to return in the results.

opts.sort
optional
Default
null
object

Specify the sort order of results.

Returns
output
object

Returns the original document.

FindOneAndReplace

airplane.mongodb.findOneAndReplace(mongodbResource, collection, update, opts)
mongodbResource
REQUIRED
string

Slug of MongoDB resource to use. See Resources

collection
REQUIRED
string

The MongoDB collection

update
REQUIRED
object

The documents to update.

opts.filter
optional
Default
null
object

Optional filter criteria. Returns all documents if filter is not provided.

opts.projection
optional
Default
null
object

Specify which fields to return in the results.

opts.sort
optional
Default
null
object

Specify the sort order of results.

Returns
output
object

Returns the original document.

InsertOne

airplane.mongodb.insertOne(mongodbResource, collection, document)
mongodbResource
REQUIRED
string

Slug of MongoDB resource to use. See Resources

collection
REQUIRED
string

The MongoDB collection

document
REQUIRED
object

The document to insert.

Returns
output.InsertedID
string

The _id of the inserted document.

Example
json
Copied
1
{
2
"InsertedID": "62c4caa466499db2981e496e"
3
}

InsertMany

airplane.mongodb.insertMany(mongodbResource, collection, document)
mongodbResource
REQUIRED
string

Slug of MongoDB resource to use. See Resources

collection
REQUIRED
string

The MongoDB collection

document
REQUIRED
object[]

The documents to insert.

Returns
output.InsertedIDs
string[]

An array containing _id values for each inserted document

Example
json
Copied
1
{
2
"InsertedIDs": ["63250df2b895dfd52a6420c3", "63250df2b895dfd52a6420c4"]
3
}

FindOneAndDelete

airplane.mongodb.findOneAndDelete(mongodbResource, opts)
mongodbResource
REQUIRED
string

Slug of MongoDB resource to use. See Resources

opts.filter
optional
Default
null
object

Optional filter criteria. Returns all documents if filter is not provided.

opts.projection
optional
Default
null
object

Specify which fields to return in the results.

opts.sort
optional
Default
null
object

Specify the sort order of results.

Returns
output
object

Returns the original document.

DeleteOne

airplane.mongodb.finddeleteOneOneAndDelete(mongodbResource, opts)
mongodbResource
REQUIRED
string

Slug of MongoDB resource to use. See Resources

opts.filter
optional
Default
null
object

Optional filter criteria. Returns all documents if filter is not provided.

opts.projection
optional
Default
null
object

Specify which fields to return in the results.

opts.sort
optional
Default
null
object

Specify the sort order of results.

Returns
output.DeletedCount
number

The number of deleted documents.

DeleteMany

airplane.mongodb.deleteMany(mongodbResource, opts)
mongodbResource
REQUIRED
string

Slug of MongoDB resource to use. See Resources

opts.filter
optional
Default
null
object

Optional filter criteria. Returns all documents if filter is not provided.

opts.projection
optional
Default
null
object

Specify which fields to return in the results.

opts.sort
optional
Default
null
object

Specify the sort order of results.

Returns
output.DeletedCount
number

The number of deleted documents.

Example
json
Copied
1
{
2
"DeletedCount": 4
3
}

Aggregate

airplane.mongodb.aggregate(mongodbResource, collection, pipeline)
mongodbResource
REQUIRED
string

Slug of MongoDB resource to use. See Resources

collection
REQUIRED
string

The MongoDB collection.

pipeline
REQUIRED
object[]

See aggregation-pipeline.

Returns
output.DeletedCount
object[]

A list of documents produced by the final stage of the aggregation pipeline operation.

CountDocuments

airplane.mongodb.countDocuments(mongodbResource, collection, filter)
mongodbResource
REQUIRED
string

Slug of MongoDB resource to use. See Resources

collection
REQUIRED
string

The MongoDB collection.

filter
REQUIRED
object

Criteria to filter by.

Returns
output
number

The count of documents that match the query.

Distinct

airplane.mongodb.distinct(mongodbResource, field, collection, filter)
mongodbResource
REQUIRED
string

Slug of MongoDB resource to use. See Resources

field
REQUIRED
string

The field to count.

collection
REQUIRED
string

The MongoDB collection.

filter
REQUIRED
object

Criteria to filter by.

Returns
output
object[]

A list of distinct values for a specified field across the searched collection or view.