easymongo
This is a small tweaks for the native MongoDB driver.
Easymongo v5 now support only Node.js v4. For previous version you can use the older easymongo.
Installation
$ npm i --save easymongo
Examples
const Client = ; let mongo = dbname: 'test';let users = mongo; let data = name: 'Alexey' surname: 'Simonenko' url: 'http://simonenko.su'; users; users; users; users; users; users;
API
Client class
Constructor
Arguments:
server
(string || object) — connection url to MongoDB or object with host, port and dbnameoptions
(object) — optional options for insert command
Methods
collection(name)
— returns a new instance of the easymongo Collection classopen(name)
— returns a Promise which resolves an object of MongoDB Collectionclose()
— close the db connection
Collection class
Methods
find([params][, options])
findOne([params][, options])
findById(oid[, fields])
save(data)
update(params, data)
remove([params])
removeById(oid)
count([params])
All methods return a Promise.
Possible find options
:
limit
— to specify the maximum number of documents (more info)skip
— to control where MongoDB begins return results (more info)sort
— to control the order of matching documents (more info)fields
— specify array of fields in returned documents, e.g.["name", "url"]
Flow control
You can use easymongo
with co for promise/generator based flow-control.
Author
License
The MIT License, see the included license.md
file.