gpt4 book ai didi

c# - 从 MongoDB 'documents' 获取所有 'collection'

转载 作者:IT老高 更新时间:2023-10-28 13:03:55 25 4
gpt4 key购买 nike

我需要在 MongoDB 中检索我的集合中的所有文档,但我不知道如何。我已经像这样宣布了我的“收藏”-

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

我按照 this 中的说明进行操作MongoDB 教程。我根据自己的需要调整了它,比如-

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

但是,我一直有以下错误-

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.

最佳答案

使用当前版本的驱动程序 (v2.0),您可以通过传递匹配所有内容的过滤器来做到这一点:

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

他们还添加了一个空过滤器 (FilterDefinition.Empty),它将在驱动程序的下一版本 (v2.1) 中提供:

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

关于c# - 从 MongoDB 'documents' 获取所有 'collection',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30453780/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com