Mongo-Data-API-SDK
Mongo Data API SDK is a library that allows to integrate the MongoDB Atlas Data API in Node.js.
Installing
Using npm:
$ npm install @nirbby-lab/mongo-data-api-sdk
Example
Initialize client.
import { MongoDBDataAPIClient } from '@nirbby-lab/mongo-data-api-sdk';
const db = new MongoDBDataAPIClient({
url: process.env.MONGO_DATA_API_URL,
dataSource: process.env.MONGO_DB_CLUSTER,
database: process.env.MONGO_DB_DATABASE,
apiKey: process.env.MONGO_DB_API_KEY
});
Performing a findOne
try {
const products = await db.findOne({
collection: 'products',
filter: { _id: { '$oid': '507f1f77bcf86cd799439011' } }
projection: { name: 1, description: -1 }
});
console.log(products.document); // Document || null
} catch (err) {
// MongoDBDataAPIException
console.log(err.message);
}