gy-easy-mongo
v0.6.2
Published
把mongo的col变成json,json内容的改变自动同步到数据库
Downloads
8
Readme
easy-mongo
通过observe,将内存中object的改动自动同步到mongo数据库中。
Usage
var easyM=require('easy-mongo');
var dbp =new easyM.DbProvider();
dbp.init('mongodb://127.0.0.1/db', {exists:['users']},function(err, db) {
if (err) return console.log(err);
easyM.createDbJson(db, {col:db.users, key:'user0'}, function(err, obj) {
if (err) return console.log(err);
obj.name='Billy';
obj.money=1000;
}
});
数据库中
db.users.findOne({_id:'user0'});
{_id:'user0', name:'Billy', money:1000}
Syntax
DbProvider
- init(connstr, opt, callback)
- connstr='[mongodb://]ip[:port]/dbname'
- opt = {exists:['usr', {data:{capped: true, size: 5000, max: 1024}}]}
- callback(err, db)