如何在新的mongo C#驱动程序中执行findAll并使之同步 [英] How to do findAll in the new mongo C# driver and make it synchronous

查看:101
本文介绍了如何在新的mongo C#驱动程序中执行findAll并使之同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用官方的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并使之同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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