是否有一个"解释查询" MongoDB的LINQ的? [英] Is there an "Explain Query" for MongoDB Linq?

查看:123
本文介绍了是否有一个"解释查询" MongoDB的LINQ的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法来运行 .explain()或等值的LINQ查询?我想知道

Is there a way to run .explain() or equivalent on Linq queries? I would want to know


  • 的实际JSON查询的文本

  • 的输出 .explain()(索引使用等)

  • 这也将是不错的查询的执行时间

  • The text of the actual JSON query
  • The output of .explain() (indexes used, etc)
  • It would also be nice to have the execution time of the query

推荐答案

您可以得到JSON的很轻松了,如果你有一个查询包装;

You can get the Json easily enough if you have a query wrapper;

var qLinq = Query<T>.Where(x => x.name=="jim");
Console.WriteLine(qLinq.ToJson());



另外还有一个解释上MongoCursor()方法,所以你可以做到这一点;

There's also an Explain() method on MongoCursor, so you could do this;

var exp = Collection.FindAs<T>(qLinq).Explain()
Console.WriteLine(exp.ToJson());



所以,如果你想要的时间拍摄,米利斯就在那里;

So if you want the time taken, "millis" is in there;

var msTaken = exp.First(x => x.Name == "millis").Value.AsInt32;

如果你有一个的IQueryable ,尝试一些像这样的;

If you have an IQueryable, try something like this;

void Do(MongoCollection col, IQueryable iq)
{
        // Json Mongo Query
        var imq = (iq as MongoQueryable<Blob>).GetMongoQuery();
        Console.WriteLine(imq.ToString());

        // you could also just do;
        // var cursor = col.FindAs(typeof(Blob), imq);
        var cursor = MongoCursor.Create(typeof(Blob), col, imq, ReadPreference.Nearest);
        var explainDoc = cursor.Explain();

        Console.WriteLine(explainDoc);
    }//Do()

这篇关于是否有一个&QUOT;解释查询&QUOT; MongoDB的LINQ的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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