[SERVER-51854] db.serverStatus () the value obtained is of type numberlong Created: 28/Oct/20  Updated: 28/Oct/20  Resolved: 28/Oct/20

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Question Priority: Major - P3
Reporter: zhenchuan ding Assignee: Edwin Zhou
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:

 Description   

db.serverStatus () the value obtained is of type numberlong

I want to use it db.serverStatus () monitor the status of Mongo, the following commands I executed and the return value

>mongo --port 27001 --eval "db.serverStatus().opcounters.command"
MongoDB shell version v4.2.3
connecting to: mongodb://127.0.0.1:27001/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("a853348d-8eac-4c6a-814b-90a9f3eb6aeb") }
MongoDB server version: 4.2.8
NumberLong(86945)

 

 

 

How to change the type of numberlong to get more intuitive data

 

 



 Comments   
Comment by Edwin Zhou [ 28/Oct/20 ]

Hi zhenchuan.ding@ptmind.com,

The mongo shell treats all numbers as floating-point values by default. The mongo shell provides the NumberLong() wrapper to handle 64-bit integers. 

I'm unsure of what you mean by "intuitive data." If you mean that you desire the stdout be the number inside of NumberLong(), then you can pipe the stdout to select the last line, and trim the rest:

$ mongo --port 27001 --eval "db.serverStatus().opcounters.command" | sed -n '5 p' | cut -d'(' -f 2 | cut -d')' -f 1
59408

The SERVER project is for bugs and feature suggestions for the MongoDB server. For issues like this, we'd like to encourage you to start by asking our community for help by posting on the MongoDB Developer Community Forums.

 

Best,

Edwin

Generated at Thu Feb 08 05:26:37 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.