标签:http blog ret com collect cti sequence ima mongod
创建一个集合存放_id
db.createCollection("counters")
加入需要自增的字段
{
"_id":"productid",
"sequence_value": 0
}
然后添加自增的js方法在mongodb库 getNextSequenceValue
function (sequenceName){
var sequenceDocument = db.counters.findAndModify(
{
query:{_id: sequenceName },
update: {$inc:{sequence_value:1}},
new:true
});
return sequenceDocument.sequence_value;
}
C#中代码调用
model.id = Convert.ToInt32(_dbs.DataBase.Eval("getNextSequenceValue(‘productid‘)").AsBsonValue);
执行完之后,再去看一下counters,是不是自增了
标签:http blog ret com collect cti sequence ima mongod
原文地址:http://www.cnblogs.com/loyung/p/7161732.html