C#BsonDocument删除元素

时间:2015-01-14 13:43:20

标签: c# bson

我有一个BsonDocument

var document =  { "$match" : 
    { 
        "resume.Id" : ObjectId("5450e7c7d7c1820e40020d10"), 
        "accountSettings.HideInfo" : false, 
        "Nationality" : { "$in" : [] }, 
        "ComName" : { "$in" : [] }, 
        "resume.code" : { "$in" : [] } 
    }
}

有没有办法删除元素

"ComName" : { "$in" : [] }

"resume.code" : { "$in" : [] }

我尝试使用

document.Values.ToBsonDocument().Remove("ComName");

但是没有工作

1 个答案:

答案 0 :(得分:1)

所以,这个问题的解决方案是:

document.GetElement("$match").Value.ToBsonDocument().Remove(‌​"ComName")

以下是解释:

1.按名称取名:

document.GetElement("$match")

2.获取元素的值:

document.GetElement("$match").Value

3.转换为BsonDocument

document.GetElement("$match").Value.ToBsonDocument()

4.按名称删除元素:

document.GetElement("$match").Value.ToBsonDocument().Remove(‌​"ComName")