Models for mongodb objects.
JavaScript
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
.gitignore
.travis.yml
LICENSE
README.md
package.json

README.md

mong

NPM Version Build Status Coverage Status NPM Downloads License

Simple models for mongodb objects.

npm install mong

Creating a collection class

var db = require('mong').create()

class User extends db.Document {
  getFullName() {
    return this.firstName + ' ' + this.lastName
  }
}

Then you can use the model:

db.connect('mongodb://localhost/mydatabase')
.then(() => {
  
  User.findOne({firstName: 'Anthony'})
  .then(doc => {
    console.log(doc.getFullName());
    doc.update({$inc: {count: 1}});
  });

  User.stream({})
  .on('data', function (user) {
    console.log(user.getFullName());
  })
  .on('end', function () {
    console.log('Node streams are cool!');
  });
});