How do I use in $in operator using the 2.0 version

2019-07-08 08:47发布

I found a lot of examples of how do use $in in the previous mongodb c# driver, but I can not find any examples on how to do it in the 2.0 version.

3条回答
唯我独甜
2楼-- · 2019-07-08 09:40

I was able to figure it out. Here is how to define the Bson document for the Find method:

BsonDocument bson = new BsonDocument("_id", new BsonDocument("$in", new BsonArray(vins)));
查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-07-08 09:41

Or, how about this

var ft = new BsonDocument("ListOfString", new BsonDocument("$in", varString));
var result = myContext.myPOCO.Find(ft);
查看更多
太酷不给撩
4楼-- · 2019-07-08 09:47

Use the AnyIn operator for the typed version:

Builders<TDocument>.Filter.AnyIn(x => x.Array,searchArray)

查看更多
登录 后发表回答