从MongoDB的'收集'获得所有'的文件“ [英] Get All 'documents' from MongoDB 'collection'

查看:284
本文介绍了从MongoDB的'收集'获得所有'的文件“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要检索所有的都是我收集MongoDB中的文件,但我无法弄清楚如何。我宣布我的'收集'这样的 -

 私有静态IMongoCollection<项目> SpeCollection = db.GetCollection<项目>(collection_Project); 

和我跟着什么是的this MongoDB的教程。我调整为我所急,想 -

  VAR文件=等待SpeCollection.Find(新项目())ToListAsync() ; 



不过,我一直有以下错误 -




MongoDB.Driver.IMongoCollection没有为查找的定义,并扩展方法[超长的东西]的最佳覆盖。查找包含非有效的参数。



解决方案

使用驱动程序的当前版本(2.0版),你可以做到这一点通过将匹配一切过滤器:

  VAR文件=等待SpeCollection.Find(_ =>真).ToListAsync(); 



他们还增加了一个空的过滤器(的 FilterDefinition.Empty ),这将抵达下一版本的驱动程序(V2.1):

  VAR文件=等待SpeCollection.Find(建设者<项目> .Filter .Empty).ToListAsync(); 


I need to retrieve all the documents that are in my collection in MongoDB, but I cannot figure out how. I have declared my 'collection' like this-

private static IMongoCollection<Project> SpeCollection = db.GetCollection<Project>("collection_Project");

And I followed what is explained in this MongoDB tutorial. I adjusted it for my needs, like-

 var documents = await SpeCollection.Find(new Project()).ToListAsync();

However, I keep having the following error-

MongoDB.Driver.IMongoCollection does not have a definition for 'Find' and the best override of the extension method [superlong stuff]. Find contains non valid arguments.

解决方案

Using the current version of the driver (v2.0) you can do that by passing a filter that matches everything:

var documents = await SpeCollection.Find(_ => true).ToListAsync();

They have also added an empty filter (FilterDefinition.Empty) which will arrive in the next version of the driver (v2.1):

var documents = await SpeCollection.Find(Builders<Project>.Filter.Empty).ToListAsync();

这篇关于从MongoDB的'收集'获得所有'的文件“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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