MongoCollection<BsonDocument> tblCount;
if (!db.CollectionExists(tblCountName))
{
db.CreateCollection(tblCountName);
}
tblCount = db.GetCollection(tblCountName);
public long Get()
{
FindAndModifyArgs arg = new FindAndModifyArgs();
arg.Query = Query.EQ("_id", "Inc");
arg.Update = Update.Inc("seq", 1L);
arg.Upsert = true;
arg.VersionReturned = FindAndModifyDocumentVersion.Modified;
var result = tblCount.FindAndModify(arg);
return result.ModifiedDocument["seq"].AsInt64;
}
本文转自94cool博客园博客,原文链接http://www.cnblogs.com/94cool/p/6383713.html,如需转载请自行联系原作者