翻译FilterDefinition< TDocument>定期JSON蒙戈查询,我可以在蒙戈shell中运行TDocument、LT、FilterDefinition、shell

2023-09-03 05:29:00 作者:关灯做的事

我有很多复杂的查询,我有时想直接核对蒙戈调试\解释()的目的。 随着新2.0+ C#的驱动程序,我不知道如何做到这一点。随着previous版本有一个东西叫; IMongoQuery;和这的工作。

I have many complex queries that I sometimes wish to check directly against Mongo for debugging \ explaining() purposes. With the newer 2.0+ c# driver, i'm not sure how to do this. With the previous version there was a thing called ;IMongoQuery; and This worked.

一个简单的例子:

FilterDefinition<LalalaEvent> filter = Builders<LalalaEvent>.Filter.Where(e=> ids.Contains(e.Id) && e.Deleted != true );

感谢。

推荐答案

如果您使用的驱动程序,这是最新的2.0.1版,你可以很容易地把该过滤器在查找运行,返回一个 IFindFluent 并打印其的ToString

If you're using the latest version of the driver, which is 2.0.1 you can easily put that filter in a Find operation, get back an IFindFluent and print its ToString:

var filter = Builders<LalalaEvent>.Filter.Where(e => ids.Contains(e.Id) && e.Deleted != true);
var findFluent = collection.Find(filter);
Console.WriteLine(findFluent);

例如对于我这种打印:

find({ "_id" : { "$in" : [1, 2, 3] }, "Deleted" : { "$ne" : true } })