Mongodb字段自增长

            MongoClient client = new MongoClient("mongodb://xxx.xxx.x.xx:27017");
            var mongServer = client.GetServer();
            var db = mongServer.GetDatabase("db_test");
            var dbclient = db.GetCollection("test");


            FindAndModifyArgs arg=new FindAndModifyArgs();
            arg.Query = Query.EQ("_id", new ObjectId("5a011a0d59f1654cdc377135"));
            arg.Update = Update.Inc("Age", 1L);
            arg.Upsert = true;
            arg.VersionReturned=FindAndModifyDocumentVersion.Modified;
            var result = dbclient.FindAndModify(arg);
            var p = result.ModifiedDocument["Age"].AsInt64;

 

posted @ 2017-12-21 14:19  逍遥帝君  阅读(1670)  评论(0编辑  收藏  举报