本文介绍了翻译FilterDefinition< TDocument>定期JSON蒙戈查询,我可以在蒙戈shell中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有很多复杂的查询,我有时想直接核对蒙戈调试\解释()的目的。随着新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 } })
这篇关于翻译FilterDefinition&LT; TDocument&GT;定期JSON蒙戈查询,我可以在蒙戈shell中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!