MongoDb queries and system.linq

2019-07-17 21:27发布

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条回答
时光不老,我们不散
2楼-- · 2019-07-17 21:50

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);
查看更多
登录 后发表回答