Scribe.js/src/writers/MongoDB.js

24 lines
597 B
JavaScript
Raw Normal View History

2016-01-22 08:22:11 -06:00
import mongoose from 'mongoose'
import EntrySchema from '../schemas/entry'
import * as JSON2 from '../libs/JSON2'
export default class MongoDB {
constructor(address = 'mongodb://localhost/scribe', debug = false) {
mongoose.set('debug', debug);
const conn = mongoose.createConnection(address);
this._debug = debug;
this._entry = conn.model('Entry', EntrySchema);
}
get Entry() {
return this._entry;
}
through(data, callback) {
new this.Entry(data).save((err, data) => {
2016-01-22 08:22:11 -06:00
if (err && this._debug) console.error(err);
callback(err, data);
});
}
}