Git Product home page Git Product logo

save-mongodb's Introduction

save-mongodb - mongodb persistence engine for save

Installation

  npm install save-mongodb

Usage

I won't bore 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: '[email protected]'}, 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()
    })

  })
})

Streaming find()

Find now has a streaming interface

var contactStore = save('Contact', { engine: saveMongodb(collection) })
  , es = require('event-stream')

contactStore.find({})
  .pipe(es.stringify())
  .pipe(process.stdout)

Credits

Paul Serby follow me on twitter @serby

Licence

Licenced under the New BSD License

save-mongodb's People

Contributors

bengourley avatar benjaminparnell avatar cronnelly avatar malixsys avatar richardgoater avatar serby avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.