@nirbby-lab/mongo-data-api-sdk
TypeScript icon, indicating that this package has built-in type declarations

2.1.2 • Public • Published

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

Package Sidebar

Install

npm i @nirbby-lab/mongo-data-api-sdk

Weekly Downloads

0

Version

2.1.2

License

ISC

Unpacked Size

14.3 kB

Total Files

10

Last publish

Collaborators

  • acyclicstudent