node mongo library
$ npm install node.mongo
const mongo = require("node.mongo")(url, {
timestamp: true, // auto add createdTime and updatedTime
createdTime: 'createdTime', // customer createdTime field (timestamp=true)
updatedTime: 'updatedTime' // customer createdTime field (timestamp=true)
});
const res = await mongo.findOne(collection,condition);
const mongo = require("node.mongo")("mongodb://localhost/test");
const query = await mongo.findOne("test",{});
- collections
- return all collections in db
- collection(name)
- return specified collection (for other methods not defined)
- count(collection,query,options)
- return number of result in specified collection
- insert(collection,data)
- insert a series of new item
- update(collection,filter,data,options)
- upsert many items
- updateOne(collection,filter,data,options)
- upsert a new item (auto upsert)
- find(collection,filter,condition,cursor)
- return a group of items (array) (cursor = false)
- return a MongoCursor object (object) (cursor = true)
- findOne(collectionName,filter,condition)
- return first item accord with filter
- femove(collectionName,filter,option)
- remove any numbers of document
- aggregate(collectionName,pipeline, options)
- Execute an aggregation framework pipeline against the collection