Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8
MongoDB Atlas Data API SDK for@nodejs
License
NotificationsYou must be signed in to change notification settings
surmon-china/mongodb-data-api
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
MongoDB AtlasData API SDK for Node.js.
npm install mongodb-data-api --save
or
yarn add mongodb-data-api
import{createMongoDBDataAPI}from'mongodb-data-api'// init by URL Endpointconstapi=createMongoDBDataAPI({apiKey:'<your_mongodb_api_key>',urlEndpoint:'https://data.mongodb-api.com/app/<your_mongodb_app_id>/endpoint/data/v1'})// or init by app IDconstapi=createMongoDBDataAPI({apiKey:'<your_mongodb_api_key>',appId:'<your_mongodb_app_id>'})// specific region and cloud of appconstapi=createMongoDBDataAPI({apiKey:'<your_mongodb_api_key>',appId:'<your_mongodb_app_id>',region:'<your_mongodb_app_region>',// e.g. us-east-1cloud:'<your_mongodb_app_cloud>'// e.g. aws})
SeeMongoDB Data API Resources.
API.findOneAPI.findAPI.insertOneAPI.insertManyAPI.updateOneAPI.updateManyAPI.replaceOneAPI.deleteOneAPI.deleteManyAPI.aggregate
- find a single document
api.findOne({dataSource:'<target_cluster_name>',database:'<target_database_name>',collection:'<target_collection_name>',filter:{name:'Surmon'}}).then((result)=>{console.log(result.document)})
- insert a single document
api.insertOne({dataSource:'<target_cluster_name>',database:'<target_database_name>',collection:'<target_collection_name>',document:{name:'Surmon',age:19}}).then((result)=>{console.log(result.insertedId)})
- run an aggregation pipeline
api.aggregate({dataSource:'<target_cluster_name>',database:'<target_database_name>',collection:'<target_collection_name>',pipeline:[{$match:{status:'urgent'}},{$group:{_id:'$productName',sumQuantity:{$sum:'$quantity'}}}]}).then((result)=>{console.log(result.documents)})
// select clusterconstclusterA=api.$cluster('a')// select databaseconstdatabaseB=clusterA.$database('b')// select collectionconstcollectionC=databaseB.$collection<C>('c')// data actionsconstdata=awaitcollectionC.findOne({filter:{/*...*/}})constresult=awaitcollectionC.insertOne({document:{/*...*/}})// -------------// chaining is equivalent to the api callapi.$cluster('a').$database('b').$collection<C>('c').findOne({filter:{}})// the same asapi.findOne<C>({dataSource:'a',database:'b',collection:'c',filter:{}})
You can specify the action request to prevent this package from lagging relative to the official one.
api.$$action('findOne',{dataSource:'...',database:'...',collection:'...',filter:{}})
You can use the original Class to implement some special requirements.
import{MongoDBDataAPI}from'mongodb-data-api'constcustomerCollection=newMongoDBDataAPI<CustomerDocument>({apiKey:'<your_mongodb_api_key>',appId:'<your_mongodb_app_id>'},{dataSource:'<target_cluster_name>',database:'<target_database_name>',collection:'<target_collection_name>'})constcustomer=awaitcustomerCollection.findOne({ ...})
# install dependenciesyarn# lintyarn lint# testyarntest# buildyarn build
Detailed changes for each release are documented in therelease notes.
About
MongoDB Atlas Data API SDK for@nodejs
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Contributors3
Uh oh!
There was an error while loading.Please reload this page.
