开发者

Update a document inside a document and inside a document

Here's my Application document

{
  "_id": "binary_stuff",
  "Name": "MyApplication",
  "Settings": [
    {
      "_id": "binary_stuff",
      "Key": "ImportDirectory",
      "Value": "C:\data",
      "Overrides": [{
             "_id": "binary_stuff",
             "NewValue": "C:\anotherData"
       }]
    },
}

I know how to add a Settings subdocument but how can I add a new Override "subsubdocument".

I tried:

var query = Query.And(Query.E开发者_运维知识库Q("_id", applicationId), Query.EQ("Settings._id", settingId));
var update = Update.AddToSetWrapped("Settings.Overrides", overrideViewModel.ToBsonDocument());
Run(database => database.Applications().Update(query, update, UpdateFlags.Upsert, SafeMode.True));

It does nothing...

Any help would be appreciated.

Thanks guys !!


I found the answer, I had to use the operational $

var query = Query.And(Query.EQ("_id", applicationId), Query.EQ("Settings._id", settingId)); 
var update = Update.AddToSetWrapped("Settings.Overrides", overrideViewModel.ToBsonDocument()); 
Run(database => database.Applications().Update(query, update, UpdateFlags.Upsert, SafeMode.True));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜