解决方法
如果您有查询包装器,您可以轻松获取Json;
var qLinq = Query<T>.Where(x => x.name=="jim"); Console.WriteLine(qLinq.ToJson());
MongoCursor还有一个Explain()方法,所以你可以这样做
var exp = Collection.FindAs<T>(qLinq).Explain() Console.WriteLine(exp.ToJson());
所以如果你想要花时间,“millis”就在那里;
var msTaken = exp.First(x => x.Name == "millis").Value.AsInt32;
如果你有一个IQueryable,请尝试这样的东西;
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()