Category: Integrations
Updated

This solution is summarized from an archived support forum post. This information may have changed. If you notice an error, please let us know in Discord.

Can I use the MongoDB Integration with Microsoft’s Cosmos DB (Mongo API)

Issue

As someone considering using Microsoft's Cosmos DB for MongoDB compatibility with Appsmith's MongoDB Integration, I need to know if it will work properly. Based on Appsmith's most recent test, conducted on October 5, 2022, the commands for finding, inserting, updating, deleting, and aggregating documents in Cosmos DB worked as expected. However, there may be features specific to Cosmos that could cause issues.

Resolution

Yes, Appsmith's MongoDB Integration can be used with Microsoft's Cosmos DB, which provides MongoDB compatibility. Our recent tests have shown that the integration works as expected for common MongoDB commands such as Find Document, Insert Document, Update Document, Delete Document, Distinct, Aggregate, Raw, and Count. However, there could be unique features specific to Cosmos DB that may not work as expected.

To use Appsmith's MongoDB Integration with Cosmos DB, you'll first need to create a Cosmos DB instance with the MongoDB API. You'll also need to obtain the connection string and the database, collection, and credentials information.

Once you have that information, you can use Appsmith's MongoDB Integration to interact with your Cosmos DB instance. Here's an example of how to use the Find Document command with Cosmos DB:

// Import the necessary modules
const MongoClient = require('mongodb').MongoClient;

// Set the connection string and database information
const uri = process.env.MONGODB_URI;
const dbName = process.env.MONGODB_DBNAME;
const colName = process.env.MONGODB_COLNAME;
const username = process.env.MONGODB_USERNAME;
const password = process.env.MONGODB_PASSWORD;

// Connect to the database
const client = new MongoClient(uri, { useNewUrlParser: true });
client.connect(err => {
const collection = client.db(dbName).collection(colName);

// Use the Find Document command to retrieve data from the database
collection.find().toArray((err, docs) => {
console.log(docs);
client.close();
});
});

In this example, we're importing the necessary modules, setting the connection string and database and collection information, and connecting to the database. Then, we're using the Find Document command to retrieve all documents from the collection. Finally, we're logging the retrieved documents and closing the database connection.

You can replace the connection string, database, collection, username, and password information with your own information to use this example with your Cosmos DB instance. You can also use other MongoDB commands with Appsmith's MongoDB Integration to interact with your Cosmos DB instance.