0
나는 mongodb에서 일반적인 기능을 가지고있다.nodejs에서 mongoose를 사용하여 함수를 생성하는 방법
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;
}
}
});
이 기능은 mongoose에서 nodejs를 사용하여 mongodb에 저장해야합니다.
도와주세요.