@clocklimited/save-mongodb - mongodb persistence engine for save
Installation
npm install @clocklimited/save-mongodb
// There is a peer dependency of mongodb - you have to bring your own!
npm install mongodb@^4
Usage
If you want to see how this works look at the tests or this simple example:
var MongoClient = require('mongodb').MongoClient
var save = require('save')
var saveMongodb = require('@clocklimited/save-mongodb')
MongoClient.connect('mongodb://localhost:27017/', function(error, client) {
if (error) return console.error(error.message)
var connection = client.db('test')
connection.collection('contact', function(error, collection) {
if (error) return console.error(error.message)
var contactStore = save('Contact', { engine: saveMongodb(collection) })
contactStore.create({ name: 'Paul', email: 'paul@serby.net' }, function(
error,
contact
) {
if (error) return console.error(error.message)
console.log(contact)
client.close()
})
})
})
Streaming find()
Find now has a streaming interface
var contactStore = save('Contact', { engine: saveMongodb(collection) })
var es = require('event-stream')
contactStore.find({})
.pipe(es.stringify())
.pipe(process.stdout)
Credits
Paul Serby follow me on twitter @serby
Clock Limited follow us on twitter @clock
Licence
Licenced under the New BSD License