mniam

Yet another mongodb facade.

npm install mniam
23 downloads in the last month

Build Status Dependency Status NPM version

mniam

Yet another mongodb native driver facade. Takes care of:

  • mongo URI parsing
  • opening and closing DB connections
  • opening collections

Install by running

npm install mniam

API

database(url, [options])

Connect to database mniam-test and create friends collection with index on name field.

var db = database('mongodb://localhost/mniam-test'),
  friends = db.collection({
    name: 'friends',
    indexes: [[{ name: 1 }]]
  });

Mniam is using MongoClient to establish the connection: full mongo database URLs are supported. The database function also takes a hash of options divided into db/server/replset/mongos allowing you to tweak options not directly supported by the unified url string format.

var db = database('mongodb://localhost/mniam-test', {
  db: {
    w: -1
  },
  server: {
    ssl: true
  }
})

collection.save

Add a new documents:

friends.save({
  name: 'Alice',
  age: 14,
}, function(err, item) {
    console.log('Item id:', item._id);
});

collection.findAndModify

Update a document:

friends.findAndModify(item._id, {
  $set: { age: 15 }
}, function(err, item) {
  console.log('Alice is now:', item.age);
})

collection.remove

Remove a document:

friends.remove({ name: 'Alice' }, function(err) {
  // last collection closed closes DB connection
  friends.close();
});

Other collection methods supported

  • collection.geonear
  • forEach
  • collection.findOne
  • collection.update

License

MIT

npm loves you