In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
MongoDB 3.0 Collective method db.collection.explain ()
Description
Db.collection.explain ()
New features in version 3.0
Returns query plan information for the following operations:
Aggregate ()
Count ()
Find ()
Group ()
Remove ()
Update ()
To use db.collection.explain (), append the above available methods to db.collection.explain () for parsing:
Db.collection.explain ().
For example:
Db.products.explain () .remove ({category: "apparel"}, {justOne:true})
For more examples, see the example section below. Using the list of available methods for db.collection.explain (), view the db.collection.explain (). Help () section.
The db.collection.explain () method takes the following parameters:
Parameter type description
Verbosity string is optional. Specifies the detail mode for parsing the output. This pattern affects the behavior of explain () and determines the amount of information returned. Possible modes are: "queryPlanner", "executionStats", and "allPlansExecution".
The default mode is "queryPlanner".
For backward compatibility with earlier versions of cursor.explain (), MongoDB identifies true as "allPlansExecution" and false as "queryPlanner".
For more information about patterns, see the details modes section.
Behavior
Detail mode
The behavior of db.collection.explain () and the amount of information returned depend on the verbosity pattern.
QueryPlanner mode
By default, db.collection.explain () runs in queryPlanner detail mode.
MongoDB runs the query optimizer to select the optimal plan for the evaluation operation.
Db.collection.explain () returns the queryPlanner information of the method being evaluated.
ExecutionStats mode
MongoDB runs the query optimizer to select the optimal plan, executes the optimal plan to complete the operation, and returns statistics that describe the execution of the optimal plan.
For write operations, db.collection.explain () returns information about the update or delete operation that will be performed, but does not apply changes to the database.
Db.collection.explain () returns queryPlanner and executionStats information for the method being evaluated. However, executionStats does not provide query execution information for abandoned plans.
AllPlansExecution mode
MongoDB runs the query optimizer to select the optimal plan and executes the optimal plan to complete the operation. In "allPlansExecution" mode, MongoDB returns execution statistics that describe the optimal plan, as well as statistics for other alternative plans during plan selection.
For write operations, db.collection.explain () returns information about the update or delete operation that will be performed, but does not apply changes to the database.
Db.collection.explain () returns queryPlanner and executionStats information for the method being evaluated. ExecutionStats contains complete query execution information for the optimal plan Boa.
If the query optimizer evaluates multiple plans, the executionStats information also contains partial execution information captured during the plan selection phase for the optimal and abandoned alternative plans.
Explain () technique
The db.collection.explain () method wraps the explain command, which is a better way to run explain.
Db.collection.explain (). Find () is similar to db.collection.find (). Explain () has the following key differences:
The 1.db.collection.explain (). Find () structure allows you to add a chain of query modifiers. List the query modifiers and view the db.collection.explain (). Find (). Help () section.
2.db.collection.explain (). Find () returns a cursor that needs to call .next (), or its alias .cursor (), to return the explain () result. If you run interactively on mongo shell,mongo shell, you will automatically call .upload () to return the result. For scripts, however, you must explicitly call .next () or .script () to return the result. List the cursor-related methods and view the db.collection.explain (). Find (). Help () section.
Db.collection.explain () .aggregate () is equivalent to passing the explain option to the db.collection.aggregate () method.
Help ()
To see a list of operations supported by db.collection.explain (), run:
Db.collection.explain () .help ()
Db.collection.explain (). Find () returns a cursor that allows you to add a chain of query modifiers. To see the list of query modifiers and cursor-related methods supported by db.collection.explain (). Find (), run:
Db.collection.explain (). Find (). Help ()
You can link multiple modifiers to db.collection.explain (). Find (). As an example, you can see the section parsing find () using modifiers.
Example
QueryPlanner mode
By default, db.collection.explain () runs in "queryPlanner" detail mode.
The following example runs db.collection.explain () in "queryPlanner" mode to return query plan information for the specified count () operation:
Db.products.explain () .count ({quantity: {$gt: 50}})
ExecutionStats mode
The following example runs db.collection.explain () in "executionStats" detail mode for the specified find () operation to return query plan and execution information:
Db.products.explain ("executionStats") .find ({quantity: {$gt: 50}, category: "apparel"})
AllPlansExecution mode
The following example runs db.collection.explain () in "allPlansExecution" detail mode. For the specified update () operation, db.collection.explain () returns the queryPlanner and executionStats of all evaluated plans:
Note:
The execution of the parsing will not modify the data, but will run a pre-query for the update operation. For alternate plans, MongoDB returns the execution information captured during the plan selection phase.
Db.products.explain ("allPlansExecution") .update ({quantity: {$lt: 1000}, category: "apparel"}, {$set: {reorder: true}})
Parse find () using modifiers
The db.collection.explain (). Find () structure allows you to query the modifier chain. For example, the following operation provides information about the find () method that uses the sort () and hint () query modifiers:
Db.products.explain ("executionStats") .find ({quantity: {$gt: 50}, category: "apparel"}) .sort ({quantity:-1}) .hint ({category: 1, quantity:-1})
Get a list of available query modifiers and run in mongo shell:
Db.collection.explain (). Find (). Help ()
Reiterate that explain (). Find () returns the cursor
Db.collection.explain (). Find () returns the cursor of the parsing result. If you run interactively on mongo shell, mongo shell automatically repeats the cursor using the. next () method. For scripts, however, you must explicitly call .next () (or its alias .script ()) to return the result:
Var explainResult = db.products.explain () .find ({category: "apparel"}) .next ()
Output
The db.collection.explain () operation can return relevant information:
1.queryPlanner, which describes the plans selected by the query optimizer and lists abandoned plans
2.executionStats, which describes the execution of the optimal plan and the abandon plan
3.serverInfo, which provides information about MongoDB instances.
The detail mode (for example: queryPlanner, executionStats, allPlansExecution) determines whether the result contains executionStats, and whether executionStats contains data captured during the plan selection phase.
For more information about the output, see the parsing results section.
For a mixed version of a sharding cluster with version 3.0 of mongos and at least one version 2.6 of mongod shard, when you run db.collection.explain () on version 3.0 of mongo shell, db.collection.explain () will retry the $explain operation to return the result in version 2.6 format.
See:
Http://docs.mongodb.org/manual/reference/method/db.collection.explain/
Http://docs.mongodb.org/manual/reference/command/explain/
Http://docs.mongodb.org/manual/reference/explain-results/
Http://docs.mongodb.org/manual/reference/operator/meta/explain/
Http://docs.mongodb.org/manual/reference/operator/query-modifier/
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.