On this page本页内容
$explain¶Deprecated since v3.0
Starting in v3.2, the 从v3.2开始,$explain operator is deprecated in the mongo shell. $explain运算符在mongo shell中不受欢迎。In the 在mongo shell, use db.collection.explain() or cursor.explain() instead.mongo shell中,请改用db.collection.explain()或cursor.explain()。
The $explain operator provides information on the query plan. $explain运算符提供有关查询计划的信息。It returns a document that describes the process and indexes used to return the query. 它返回一个文档,描述用于返回查询的过程和索引。This may provide useful insight when attempting to optimize a query. 这可能会在尝试优化查询时提供有用的见解。For details on the output, see cursor.explain().有关输出的详细信息,请参阅cursor.explain()。
You can specify the 可以使用以下任一形式指定$explain operator in either of the following forms:$explain运算符:
In the 在mongo shell, you also can retrieve query plan information through the explain() method:mongo shell中,还可以通过explain()方法检索查询计划信息:
$explain runs the actual query to determine the result. $explain运行实际查询以确定结果。Although there are some differences between running the query with 虽然使用$explain and running without, generally, the performance will be similar between the two. $explain运行查询和不使用$explain运行查询之间存在一些差异,但通常情况下,两者的性能相似。So, if the query is slow, the 因此,如果查询速度慢,$explain operation is also slow.$explain操作也慢。
Additionally, the 此外,$explain operation reevaluates a set of candidate query plans, which may cause the $explain operation to perform differently than a normal query. $explain操作会重新评估一组候选查询计划,这可能会导致$explain操作的执行方式与普通查询不同。As a result, these operations generally provide an accurate account of how MongoDB would perform the query, but do not reflect the length of these queries.因此,这些操作通常可以准确地描述MongoDB将如何执行查询,但不能反映这些查询的长度。
See also参阅
explain()