问题描述
我正在使用官方的C#驱动程序来执行FindAll
,并升级到了新的驱动程序2.0. FindAll
已过时,并用查找"代替.我正在尝试转换一个简单的方法,该方法向我返回Class1
的列表.不能在他们的文档中使用POCO找到一个现实的例子
I was using official C# driver to do a FindAll
and upgraded to the new driver 2.0. FindAll
is obsolete and is replaced with Find. I am trying to convert a simple method that returns me a list of Class1
. Cant find a realistic example using a POCO in their documentation
var collection = database.GetCollection<ClassA>(Collection.MsgContentColName);return collection.FindAll().ToList();
var collection = database.GetCollection<ClassA>(Collection.MsgContentColName);return collection.FindAll().ToList();
有人可以帮我转换2.0驱动程序并返回列表而不是任务吗?
Can someone please help me convert with 2.0 driver and return a list and not a task?
推荐答案
您可以使用2.0驱动程序来做到这一点,
you could do this to achieve the same using 2.0 driver,
var collection = database.GetCollection<ClassA>(Collection.MsgContentColName);
var doc = collection.Find(filter).ToListAsync();
doc.Wait();
return doc.Result;
这篇关于如何在新的mongo C#驱动程序中执行findAll并使之同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!