find-and-modify-stream
v1.0.1
Published
MongoDB find and modify object write stream
Downloads
47
Maintainers
Readme
find-and-modify-stream
MongoDB find and modify object write stream
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 fromMongoClient.connect
collection
- the collection name to perform the operation on
Optional options:
query
- a function used to construct the query for thefindAndModify
operation. Defaults to:function (obj) { return { _id: obj._id }}
queryOptions
- an object of options passed to thefindAndModify
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