Skip to content

OliverJAsh/save-mongodb

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

save-mongodb - mongodb persistence engine for save

Installation

  npm install save-mongodb

Usage

I won't boar your with waffle. If you want to see how this works look at the tests or this simple example:

// What you'll need!
var Db = require('mongodb').Db // npm install mongodb
  , Server = require('mongodb').Server
  , save = require('save') // npm install save
  , saveMongodb = require('..')

  // Create a db object to a local mongodb database called SimpleExample.
  , db = new Db('SimpleExample', new Server('localhost', 27017, {}));

// Open your mongodb database.
db.open(function (error, connection) {

  // Get a collection. This will create the collection if it doesn't exist.
  connection.collection('contact', function (error, collection) {

    // Create a save object and pass in a mongodb engine.
    var contactStore = save('Contact', { engine: saveMongodb(collection) });

    // Then we can create a new object.
    contactStore.create({ name: 'Paul', email: 'paul@serby.net'}, function (error, contact) {

      // The created 'contact' is returned and has been given an _id
      console.log(contact);

      // Don't forget to close your database connection!
      connection.close();
    });

  });
});

Credits

Paul Serby follow me on twitter @serby

Licence

Licenced under the New BSD License

About

mongodb persistence engine for save

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%