MongoDB的查询和System.Linq的 [英] MongoDb queries and system.linq
问题描述
当我使用System.Linq的查询在MongoCollection对象:
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?
比如SetSkip创建MongoDB中查询,但跳过它在内存中。
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?
推荐答案
的。因为它是在
查找$ C $的结果执行,其中
查询内存通过 IEnumerable.Where
完成C>呼叫建立MongoDB的查询来执行。
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.
要纳入。凡
查询到查找
,您可以创建两个查询ANDS在一起的新的查询:
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);
这篇关于MongoDB的查询和System.Linq的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!