![](/img/trans.png)
[英]how to create the collection in mongodb without any document using mongoose in nodejs
[英]How to create a function using mongoose in nodejs
我在mongodb中有一个常规功能。
db.system.js.save({_id: "Apps",value : function (doc, targetCollection) {
while (1) {
var cursor = db.targetCollection.find( {}, { App_id: 1 } ).sort( { _id: -1 } ).limit(1);
var seq = cursor.hasNext() ? cursor.next().App_id + 1 : 1;
doc.App_id = seq;
db.targetCollection.insert(doc);
var err = db.getLastErrorObj();
if( err && err.code ) {
if( err.code == 11000 /* dup key */ )
continue;
else
print( "unexpected error inserting data: " + tojson( err ) );
}
break;
}
}
});
我需要通过nodejs使用mongoose将此函数保存在mongodb中。
请帮我做到这一点。
默认情况下,Mongoose无法做到这一点。
您应该尝试使用此软件包: https : //npmjs.org/package/mongoose-function
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.