我尝试为mongoDB实现getNextSequence
函数解释Link我使用lattes C#驱动程序,但我不确定如何映射{{1} } FindOneAndUpdateOptions
MongoDB代码
new : true
C#代码
function getNextSequence(name) {
var ret = db.counters.findAndModify(
{
query: { _id: name },
update: { $inc: { seq: 1 } },
new: true,
upsert: true
}
);
return ret.seq;
}
答案 0 :(得分:3)
FindOneAndUpdateOptions
有ReturnDocument
枚举
ReturnDocument.Before ='new':false
ReturnDocument.After ='new':true
在您的情况下,选项应为:
var options = new FindOneAndUpdateOptions<ObjectSequence, ObjectSequence>() { ReturnDocument = ReturnDocument.After, IsUpsert = true };