MongoDB .NET Driver 2.0中的FindAll [英] FindAll in MongoDB .NET Driver 2.0

查看:102
本文介绍了MongoDB .NET Driver 2.0中的FindAll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在没有任何过滤器的情况下使用MongoDB .NET Driver 2.0查询我的MongoDB集合,但找不到任何方法.我有以下解决方法,但看起来很奇怪:D

I want to query my MongoDB collection without any filter with MongoDB .NET Driver 2.0 but I didn't find a way. I have the following workaround but it looks weird :D

var filter = Builders<FooBar>.Filter.Exists(x => x.Id);
var fooBars = await _fooBarCollection.Find(filter)
    .Skip(0)
    .Limit(100)
    .ToListAsync();

在MongoDB .NET Driver 2.0中是否可以在没有过滤器的情况下发出查询?

Is there a way to issue queries without a filter in MongoDB .NET Driver 2.0?

推荐答案

没有过滤器就不能使用Find.

You can't use Find without a filter.

不过,您可以使用可以传递所有内容的过滤器:

You can however use a filter that passes everything:

var findFluent = await _fooBarCollection.Find(_ => true);

或者您可以使用等效的空文档:

Or you can use an empty document which is equivalent:

var findFluent = await _fooBarCollection.Find(new BsonDocument());

他们还添加了一个空的过滤器,但仅在驱动程序的较新版本中可用:

They have also added an empty filter but it will only be available in newer versions of the driver:

var findFluent = await _fooBarCollection.Find(Builders<FooBar>.Filter.Empty);

这篇关于MongoDB .NET Driver 2.0中的FindAll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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