开发者

Update a document inside a document and inside a document

开发者 https://www.devze.com 2023-03-16 23:29 出处:网络
Here\'s my Application document { \"_id\": \"binary_stuff\", \"Name\": \"MyApplication\", \"Settings\": [

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

精彩评论

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