我有這個問題:我想通過代碼獲取下一個序列號,但它總是說「未定義」。從mongodb allways得到sequnce號碼undefined
任何幫助將是爐排:)
我以前做這在我的MongoDB:
db.PresentationCollection.insert(
{
_id: "editorID",
seq: 0
}
)
我的代碼(名稱是editorID):
function getNextSequence(name, db) {
var collection = db.get('PresentationCollection');
var ret = collection.findAndModify(
{
query: { _id: name },
update: { $inc: { seq: 1 } },
new: true
}
);
return ret.seq;
}
0123對不起,我想我的語法錯誤,你能寫一些有用的東西嗎? – eran10