Join us at MongoDB.local London on 7 May to unlock new possibilities for your data. Use WEB50 to save 50%.
Register now >
Docs Menu
Docs Home
/ /
Funciones

Consulta de MongoDB Atlas

Puede trabajar con datos en una fuente de datos MongoDB vinculada desde una función mediante un cliente de fuente de datos integrado. Este cliente incluye métodos que permiten leer, escribir y agregar datos.

For examples of how to work with a data source in a function, refer to the following guides:

Para obtener información de referencia detallada sobre los métodos de consulta y agregación disponibles, consulte Referencia de API de MongoDB.

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
})
}

Volver

Funciones