about db.serverStatus() shows something confused

272 views
Skip to first unread message

leo ma

unread,
Jul 22, 2016, 3:53:40 AM7/22/16
to mongodb-user

db.serverStatus().opcounters.query
30

db.serverStatus().metrics.commands.find
{ "failed" : NumberLong(0), "total" : NumberLong(7) }

why  they are not same 


some other operations but find  are belonged to query ?


what are these operaions  ?

so  anyone  knows it ?

Senthilkumar Kamaraj

unread,
Jul 23, 2016, 5:12:04 PM7/23/16
to mongodb-user
I believe the first operation showed the total number of available opcounter.  for the second there was condition 'Failed' and it was not satisfy the condition. 

Wan Bachtiar

unread,
Aug 4, 2016, 1:14:11 AM8/4/16
to mongodb-user

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.

leo ma

unread,
Aug 14, 2016, 10:23:20 PM8/14/16
to mongodb-user
but could u write some examples ,I have read  the user manual  but I can't  repeat this operation just like  only opcounters.query increase ,command.find not ,or command.find failed increae

current verstion 3.2.8

tks

在 2016年8月4日星期四 UTC+8下午1:14:11,Wan Bachtiar写道:

Wan Bachtiar

unread,
Aug 17, 2016, 9:09:08 PM8/17/16
to mongodb-user

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:

  • MongoDB driver language and version
  • MongoDB mongo shell version
  • MongoDB deployment topology i.e. standalone, replica set, or sharded cluster.

Regards,

Wan.

Reply all
Reply to author
Forward
0 new messages