find-and-modify-stream

1.0.1 • Public • Published

find-and-modify-stream

MongoDB find and modify object write stream

build status

Installation

npm install find-and-modify-stream --save

Usage

var MongoStream = require('find-and-modify-stream')
var MongoClient = require('mongodb').MongoClient
 
MongoClient.connect('mongodb://localhost:27017/database-name', function (err, db) {
  var stream = new MongoStream({ connection: db, collection: 'collection-name' })
 
  stream.on('finish', function () {
    process.exit(0)
  })
 
  stream.write({ a: 1 })
  stream.write({ b: 2 })
  stream.end()
 
})
 

var writeStream = MongoStream(options)

Options must include:

  • connection - a database connection returned from MongoClient.connect
  • collection - the collection name to perform the operation on

Optional options:

  • query - a function used to construct the query for the findAndModify operation. Defaults to: function (obj) { return { _id: obj._id }}
  • queryOptions - an object of options passed to the findAndModify operation. Can be used to modify write concerns and upsert preferences. Defaults to: { upsert: true, w: 1, fsync: true }

Credits

Dom Harrington follow me on twitter @domharrington

Package Sidebar

Install

npm i find-and-modify-stream

Weekly Downloads

2

Version

1.0.1

License

ISC

Last publish

Collaborators

  • domharrington