MongoDb use filter to match a list

蓝咒 提交于 2019-11-28 02:19:15

You'll have to extract the _id from the BsonDocument like this:

var extractedIds = myIds.Select(x => x["_id"].ToString()).ToList();

After which you can use it in the filter.

list.DeleteMany(Builders<MessageExchange>.Filter.In("_id", extractedIds));

Make sure that the _id part of the filter matches that of the MessageExchange class

Another way to do so is by making it strong typed:

list.DeleteMany(Builders<MessageExchange>.Filter.In(x => x.Id, extractedIds));

This works as well (based on Skami's answer):

var filter = new BsonDocument("_id", new BsonDocument("$in", new BsonArray(extractedIds)));
list.DeleteMany(filter);

therefore is not tied to the MessageExchange class.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!