Query MongoDB Atlas
Atlas Device Sync, Atlas Edge Server, Data API, and HTTPS Endpoints are deprecated. Refer to the deprecation page for details.
You can work with data in a linked MongoDB Data Source from a function by using a built-in data source client. The client includes methods that allow you to read, write, and aggregate data.
For examples of how to work with a data source in a function, refer to the following guides:
For detailed reference information on available query and aggregation methods, see MongoDB API Reference.
exports = async function() { // 1. Get a data source client const mongodb = context.services.get("mongodb-atlas"); // 2. Get a database & collection const db = mongodb.db("myDatabase") const collection = db.collection("myCollection") // 3. Read and write data with MongoDB queries await collection.insertOne({ text: "Hello, world!", author: context.user.id }) return await collection.findOne({ author: context.user.id }) }