why they are not same some other operations but find are belonged to query ?
Hi Leo,
To answer your question, let’s first review their definitions.
The output section of db.serverStatus() for opcounters.query returns the total number of queries received since the mongod instance last started. The total number returned includes unsuccessful queries.
While the output section of db.serverStatus() for metrics.commands.find returns a document report for find query via database commands. The failed field in this case represents the number of unsuccessful find command i.e. invalid collection name.
Note that find() since version 3.2 is a database command. This means any db.collection.find() is operated as db.runCommand({find:"collection"}) in v3.2+, and will increment both counter of opcounters.query and metrics.commands.find.
If you are on a MongoDB version previous to v3.2, any db.collection.find() will be counted only towards opcounters.query. Any other query commands such as findAndModify command will only increment metrics.commands.find.
For more information please see serverStatus() output manual.
Regards,
Wan.
but could u write some examples
Hi Leo,
If you are using MongoDB v3.2.x, you could have a higher count for opcounters.query than metrics.commands.find if you connect using a legacy connection (older version of driver or mongo shell).
For example, if you use PyMongo version 3.1 (or older) to execute query find this will increase only opcounters.query value.
See also Driver Version Compatibility
If you still have further questions please provide the following relevant information:
mongo shell versionRegards,
Wan.