Scribe.js/src/writers/MongoDB.js
2016-01-24 18:03:01 -06:00

24 lines
No EOL
597 B
JavaScript

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) => {
if (err && this._debug) console.error(err);
callback(err, data);
});
}
}