mongo-lazy
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.
Installation
npm install mongo-lazy
Usage
node --harmony yourScript.js
The --harmony flag is necessary because we're using Harmony proxies to open and cache collections transparently.
Example
var db = require('mongo-lazy').open({
db: 'yummy',
host: 'ds037987.mongolab.com',
port: 37987,
user: 'guest',
password: '123456'
});
db.drink.findOne({name: 'Dom Perignon'}, function(err, domPerignon) {
console.log('A good wine:\n', err || domPerignon, '\n');
});
db.meal.findAll({from: 'France'}, function(err, frenchMeals) {
console.log('French meals:\n', err || frenchMeals, '\n');
});
db([
['drink', 'findOne', {price: 'free'}],
['meal', 'findOne', {price: 'cheap'}],
['dessert', 'findAll', {quality: "good"}, {fields: {name: 1, _id: 0}}]
], function(err, drink, meal, desserts) {
if (err) throw err;
console.log('Drink:\n', drink);
console.log('Meal:\n', meal);
console.log('Desserts:\n', desserts, '\nBon appetit!\n');
});
setTimeout(function() {
db.close();
}, 3000);
Using the underlying mongodb-native Db
object
The documentation of the mongodb-native Db
object is here.
To access and manipulate the underlying mongodb-native Db
object,
there are 3 hooks on the mongo-lazy db
object:
db.close()
to close the databasedb.ready(listener)
to attach a listener which will be fired when Db
is readydb.$
which is the mongodb-native Db
object itself (or null
when Db
is not ready)
MIT License
Copyright (c) 2012 Jie Meng-Gerard contact@jie.fr
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.