Docs Menu

Docs HomeAtlas App Services

Query MongoDB Atlas

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 ="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!",
return await collection.findOne({
←  Atlas FunctionsRead Data from MongoDB Atlas - Functions →
Share Feedback
© 2023 MongoDB, Inc.


  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2023 MongoDB, Inc.