MongoDb queries and system.linq

别来无恙 提交于 2019-12-24 05:30:09

问题


When i use System.linq to query objects in a MongoCollection:

var result = collection.Find(query).Where(x => x.something == something);

is this a query done on the database or on the collection in memory?

for instance "SetSkip" creates the query in MongoDb but "Skip" does it in memory.

If ".Where" is done in memory is there a way not to do this?


回答1:


The .Where query is done in memory via IEnumerable.Where because it's performed on the result of the Find call that establishes the MongoDB query to perform.

To incorporate the .Where query into the Find, you can create a new query that ANDs the two queries together:

query = Query.And(query, Query<YourType>.EQ(x => x.something, something));
var result = collection.Find(query);


来源:https://stackoverflow.com/questions/26692213/mongodb-queries-and-system-linq

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