Node-mongodb-native for lazy people. Don't ever open a collection again. Eat a piece of cake while doing parallel queries.
All the methods of node-mongodb-native are available. See the official documentation.
npm install mongo-lazy
node --harmony yourScript.js
The --harmony flag is necessary because we're using Harmony proxies to open and cache collections transparently.
// Open a db w/ the 3 args of mongodb.Db(dbName, servConfig, options) or w/ 1 obj-arg like abovevar db =;// No need to open collections anymore, just call them as you would usually do with the mongo CLIdbdrink;// The 'findAll' method returns all the elements of a collection (equiv to find + toArray)dbmeal;// Easy parallel queries: callback returns when all queries return or earlier if an error happened;// Closing DB after 3 seconds;
Using the underlying mongodb-native
The documentation of the mongodb-native
Db object is here.
To access and manipulate the underlying mongodb-native
there are 3 hooks on the mongo-lazy
db.close()to close the database
db.ready(listener)to attach a listener which will be fired when the mongodb-native
db.$which is the mongodb-native
Dbobject itself (or
Dbis not ready)
Copyright (c) 2012 Jie Meng-Gerard firstname.lastname@example.org
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.