删除与mongodb c#

时间:2015-11-29 04:55:03

标签: c# mongodb mongodb-.net-driver

我试图从符合条件的嵌套数组中删除所有元素,我的文档如下所示:

{
"_id" : ObjectId("5658a636742a2f0bd8bfe3f1"),
"Name" : "Ade",
"Groups" : [ 
    {
        "_id" : ObjectId("565a4d79742a2f14f8d42239"),
        "Name" : "GrupoA",
        "Members" : [ 
            "F", 
            "B"
        ]
    }, 
    {
        "_id" : ObjectId("565a4df2742a2f14f8d4223a"),
        "Name" : "GrupoB",
        "Members" : [ 
            "A", 
            "B", 
            "C"
        ]
    }
]}

我使用的代码是:

var filter = Builders<ApplicationUser>.Filter.ElemMatch(x => x.Groups, y => y.Members.Contains("B"));
var updateDefinition =  Builders<ApplicationUser>.Update.Pull("Groups.$.Members", "B");
collection.UpdateManyAsync(filter, updateDefinition);

但是当我执行它时,它只删除&#34; B&#34;来自&#34; GrupoA&#34;,我想删除所有&#34; B&#34;在数组中找到。

0 个答案:

没有答案