MongoDB的查询和System.Linq的 [英] MongoDb queries and system.linq

查看:730
本文介绍了MongoDB的查询和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?

推荐答案

。因为它是在查找查询内存通过 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆