MongoDB (Preview)

MongoDB is a general purpose, distributed, document data platform which is loved by developers and used across enterprises to run variety of workloads.You can now explore the various endpoints and perform CRUD operations and aggregations on your collection using the MongoDB Connector.

This connector is available in the following products and regions:

Service Class Regions
Logic Apps Standard All Logic Apps regions except the following:
     -   Azure Government regions
     -   Azure China regions
     -   US Department of Defense (DoD)
Power Automate Premium All Power Automate regions except the following:
     -   US Government (GCC)
     -   US Government (GCC High)
     -   China Cloud operated by 21Vianet
     -   US Department of Defense (DoD)
Power Apps - Not available
Contact
Name MongoDB Support
URL https://www.mongodb.com/community/forums/
Email [email protected]
Connector Metadata
Publisher MongoDB
Website https://www.mongodb.com
Privacy policy https://www.mongodb.com/legal/privacy-policy
Categories Data

MongoDB Connector provides a simple way to connect to MongoDB Atlas via Atlas Data API to read and write data to MongoDB Atlas collections. MongoDB connector makes it easy to perform CRUD operations and aggregations on your data in minutes and allows you to query MongoDB to build rich apps and workflows in Power Apps and Power Automate.

Prerequisites

  1. Configure Atlas Environment

Register for a new Atlas Account here. Follow steps from 1 to 4 (Create an Atlas account, Deploy a Free cluster, Add your IP to the IP access list and Create a Database user) to set up the Atlas environment.

  1. Enable the Data API in Atlas here.

Under Data API Access dropdown, choose Read And Write option.

Save the URL endpoint which will be used at a later stage.

  1. Create a Data API Key here

Note: Save the api key generated as this is the only time you can retrieve the full private key.

How to get credentials

Follow the steps in Create a Data API Key to create API key in Atlas and use it in the API calls

Get started with your connector

Once the Prerequisites are completed, Go to PowerAutomate-> Data-> Connections. Click on "New Connection" and search for MongoDB in the right Search Bar like shown below in the screenshot.

image

Click on the MongoDB connection and you would see the below popup which asks to enter the API key and the Base URL.

image

1: For the "API Key" field, enter the Data API key which you would have set up in the Step 3

2: For the "BaseUrl", enter the URL Endpoint you find in the MongoDB Atlas portal-> Data API.

Use one of the Data APIs for any CRUD operations against MongoDB Atlas. For complex queries, use the "Run an Aggregation Pipeline" API to use aggregation stages to massage the output from one stage to another. The flexibility and dynamism of MongoDB allows you to create rich apps and automate any time consuming processes. You keep enhancing the apps by adding more features and fields to the same collection.

Additionally, check Appsource for a hands-on demo of a Banking Customer Onboarding application built using Power Apps, Power Automate and MongoDB Atlas. The Github link for the same is here.

Known issues and limitations

As MongoDB does not enforce a schema, the current connector can be used with Power Automate and Logic Apps only, which supports dynamic schema for the API response, which can then be parsed using the "Parse JSON" constructs. It can be used in Power Apps by invoking a Power Automate flow for every MongoDB interaction. You can also continue to use the certified MongoDB connector from the Microsoft Github repository as a Custom connector to use it in Power Apps directly to customize the Response schema as per your MongoDB collection schema.

Restrictions applicable to MongoDB Data API does apply to the MongoDB connector also. Please refer to this link to know more about the aggregation stages that are not supported under User context of Data APIs.

Please follow this link for the known limitations with the requests

Common errors and remedies

Please follow this link for common error codes and this link for known failure due to request traffic limitations

Creating a connection

The connector supports the following authentication types:

Default Parameters for creating connection. All regions Not shareable

Default

Applicable: All regions

Parameters for creating connection.

This is not shareable connection. If the power app is shared with another user, another user will be prompted to create new connection explicitly.

Name Type Description Required
API Key securestring The API Key for this api True
BaseUrl string the Base url (Example:https://data.mongodb-api.com/app//endpoint/data/v1) True

Throttling Limits

Name Calls Renewal Period
API calls per connection 100 60 seconds

Actions

Delete Document

To delete a single document, use the deleteOne endpoint. Use the filter property in the request body to specify the search criteria. If more than one document matches the criteria, only the first match will be deleted.

Delete Many Documents

You can use deleteMany to delete multiple documents at once. Use the filter property to specify which documents to delete. Beware that using this API without any filters will delete all the documents in the collection. Use deletemany with care.

Find Document

Using the findOne endpoint will let you retrieve a single document from a collection. Use the filter property in the request body to specify the search criteria. If more than one document matches the criteria, only the first match will be returned.

Find Multiple Documents

Using the find endpoint, you can fetch multiple documents at once. Use the filter property in the body of the request to specify the criteria on which to filter. If you pass an empty object, all the documents in the collection will be returned.

Insert Document

Using the insertOne endpoint, you can add a document to a collection. Use the document property in the request body to specify the document that should be created.

Insert Multiple Documents

You can add more than one document at a time by using the insertMany endpoint. In that case, you must use the documents property in the body of the request to specify the array of documents you want to insert into the collection.

Run Aggregation Pipeline

You can even run aggregation pipelines with the Data API. To do so, use the aggregate endpoint and specify your pipeline in the pipeline field of the request body.

Update Document

You can use the updateOne endpoint to update a single record. Use the filter property in the request body to specify the search criteria. If more than one document matches the criteria, only the first match will be returned. Then use the update field to specify what should be updated. You should use one of the update operators to update your documents.

Update Multiple Documents

Using updateMany, you can update all the documents matching a specific filter specified in the body of the request. Use one of the update operators in the update field to update your documents.

Delete Document

To delete a single document, use the deleteOne endpoint. Use the filter property in the request body to specify the search criteria. If more than one document matches the criteria, only the first match will be deleted.

Parameters

Name Key Required Type Description
MongoDB Cluster Name
dataSource True string

The name of the cluster.

MongoDB Database Name
database True string

The name of the database.

MongoDB Collection Name
collection True string

The name of the collection.

filter
filter True object

A MongoDB Query Filter. The deleteOne action deletes the first document in the collection that matches this filter.

Returns

Name Path Type Description
deletedCount
deletedCount integer

deletedcount

Delete Many Documents

You can use deleteMany to delete multiple documents at once. Use the filter property to specify which documents to delete. Beware that using this API without any filters will delete all the documents in the collection. Use deletemany with care.

Parameters

Name Key Required Type Description
MongoDB Cluster Name
dataSource True string

The name of the cluster.

MongoDB Database Name
database True string

The name of the database.

MongoDB Collection Name
collection True string

The name of the collection.

filter
filter True object

A MongoDB Query Filter . The deleteMany action deletes all documents in the collection that match this filter.

Returns

Name Path Type Description
deletedCount
deletedCount integer

deletedCount

Find Document

Using the findOne endpoint will let you retrieve a single document from a collection. Use the filter property in the request body to specify the search criteria. If more than one document matches the criteria, only the first match will be returned.

Parameters

Name Key Required Type Description
MongoDB Cluster Name
dataSource True string

The name of the cluster.

MongoDB Database Name
database True string

The name of the database.

MongoDB Collection Name
collection True string

The name of the collection.

filter
filter object

A MongoDB Query Filter. The findOne action returns the first document in the collection that matches this filter.

projection
projection object

A MongoDB Query Projection. Depending on the projection the returned document will either omit specific fields or include only specified fields or values

Returns

Name Path Type Description
document
document object

document

Find Multiple Documents

Using the find endpoint, you can fetch multiple documents at once. Use the filter property in the body of the request to specify the criteria on which to filter. If you pass an empty object, all the documents in the collection will be returned.

Parameters

Name Key Required Type Description
MongoDB Cluster Name
dataSource True string

The name of the cluster.

MongoDB Database Name
database True string

The name of the database.

MongoDB Collection Name
collection True string

The name of the collection.

filter
filter object

A MongoDB Query Filter.The find action returns documents in the collection that match this filter.If you do not specify a filter, the action matches all document the collection.

projection
projection object

A MongoDB Query projection.Depending on the projection, the returned documents either omit specific fields or include only specified fields and values.

sort
sort object

A MongoDB Sort Expression. Matched documents are returned in ascending or descending order of the fields specified in the expression.

limit
limit integer

The maximum number of matched documents to include in the returned result set. Each request may return up to 50,000 documents.

skip
skip integer

The number of matched documents to skip before adding matched documents to the result set.

Returns

Name Path Type Description
documents
documents array of object

documents

items
documents object

Insert Document

Using the insertOne endpoint, you can add a document to a collection. Use the document property in the request body to specify the document that should be created.

Parameters

Name Key Required Type Description
MongoDB Cluster Name
dataSource True string

The name of the cluster.

MongoDB Database Name
database True string

The name of the database.

MongoDB Collection Name
collection True string

The name of the collection.

document
document True object

An EJSON document to insert into the collection.

Returns

Name Path Type Description
insertedId
insertedId string

insertedId

Insert Multiple Documents

You can add more than one document at a time by using the insertMany endpoint. In that case, you must use the documents property in the body of the request to specify the array of documents you want to insert into the collection.

Parameters

Name Key Required Type Description
MongoDB Cluster Name
dataSource True string

The name of the cluster.

MongoDB Database Name
database True string

The name of the database.

MongoDB Collection Name
collection True string

The name of the collection.

documents
documents object

items

Returns

Name Path Type Description
insertedIds
insertedIds array of string

insertedIds

Run Aggregation Pipeline

You can even run aggregation pipelines with the Data API. To do so, use the aggregate endpoint and specify your pipeline in the pipeline field of the request body.

Parameters

Name Key Required Type Description
MongoDB Cluster Name
dataSource True string

The name of the cluster.

MongoDB Database Name
database True string

The name of the database.

MongoDB Collection Name
collection True string

The name of the collection.

pipeline
pipeline object

items

Returns

Name Path Type Description
documents
documents array of object

documents

items
documents object

Update Document

You can use the updateOne endpoint to update a single record. Use the filter property in the request body to specify the search criteria. If more than one document matches the criteria, only the first match will be returned. Then use the update field to specify what should be updated. You should use one of the update operators to update your documents.

Parameters

Name Key Required Type Description
MongoDB Cluster Name
dataSource True string

The name of the cluster.

MongoDB Database Name
database True string

The name of the database.

MongoDB Collection Name
collection True string

The name of the collection.

filter
filter True object

A MongoDB Query Filter.The UpdateOne action modifies the first document in the collection that matches this filter.

update
update True object

A MongoDB Update Expression that specifies how to modify the matched document.

upsert
upsert boolean

The Upsert flag only applies if no documents match the specified filter. If true, the updateOne action inserts a new document that matches the filter with the specified update applied to it.

Returns

Name Path Type Description
matchedCount
matchedCount integer

matchedcount

modifiedCount
modifiedCount integer

modifiedcount

Update Multiple Documents

Using updateMany, you can update all the documents matching a specific filter specified in the body of the request. Use one of the update operators in the update field to update your documents.

Parameters

Name Key Required Type Description
MongoDB Cluster Name
dataSource True string

The name of the cluster.

MongoDB Database Name
database True string

The name of the database.

MongoDB Collection Name
collection True string

The name of the collection.

filter
filter True object

A MongoDB Query Filter . The updateMany action modifies all documents in the collection that match this filter.

update
update True object

A MongoDB Update Expression that specifies how to modify matched documents.

upsert
upsert boolean

The upsert flag only applies if no documents match the specified filter. If true, the updateMany action inserts a new document that matches the filter with the specified update applied to it.

Returns

Name Path Type Description
matchedCount
matchedCount integer

matchedcount

modifiedCount
modifiedCount integer

modifiedcount