📜  addFields - 任何代码示例

📅  最后修改于: 2022-03-11 14:55:20.646000             🧑  作者: Mango

代码示例1
var pipeline = new BsonDocumentStagePipelineDefinition(
                 new[] { 
                   new BsonDocument{{"$addFields", 
                     new BsonDocument{{"NextValue", 
                       new BsonDocument{{ "$sum", new BsonArray().Add("$seq").Add(1) } } 
                     }}
                   }},
                   new BsonDocument{{"$addFields", 
                     new BsonDocument{{"Obj", 
                       new BsonDocument("name", "hi2").Add("val", "$NextValue")
                     }}
                   }} 
                 } 
);
var updateDefinition = new PipelineUpdateDefinition(pipeline);
var result = collection.UpdateOne(new BsonDocument{}, updateDefinition);