How do I use in $in operator using the 2.0 version of the C# mongodb driver?

你说的曾经没有我的故事 提交于 2020-01-03 21:14:31

问题


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.


回答1:


Use the AnyIn operator for the typed version:

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




回答2:


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:


Or, how about this

var ft = new BsonDocument("ListOfString", new BsonDocument("$in", varString));
var result = myContext.myPOCO.Find(ft);


来源:https://stackoverflow.com/questions/33393696/how-do-i-use-in-in-operator-using-the-2-0-version-of-the-c-sharp-mongodb-driver

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