How can I delete nested array element in a mongodb document with the c# driver

前端 未结 6 1760
没有蜡笔的小新
没有蜡笔的小新 2021-02-14 08:21

I am new in the MongoDB world and now I am struggling of how can I delete, update element in a nested array field of a document. Here is my sample document:

{
           


        
6条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-14 08:44

    Solution with C# MongoDB Driver. Delete a single nested element.

    var filter = Builders.Filter.Where(ym => ym.Id == ymId);
    var update = Builders.Update.PullFilter(ym => ym.NestedItems, Builders.Filter.Where(nm => nm.Id == nestedItemId));
    _repository.Update(filter, update);
    

提交回复
热议问题