Converting Mongo Extended JSON format to strict JSON on MongoDB shell

578 views
Skip to first unread message

an...@cultureamp.com

unread,
Jun 30, 2015, 8:46:02 PM6/30/15
to mongod...@googlegroups.com
Hi there,

maybe a bit of an obvious question but can't find the answer.

I am trying to extract Server Status information from a mongodb instance to be fed it into Splunk.


At the moment I am using the following script:

mongo ... --quiet --eval "printjsononeline(db.runCommand({ serverStatus: 1 }))"



Splunk Forwarder is having issues to parse the output due to data types included in the resulting document, i.e:

"uptimeMillis" : NumberLong(522262234)



I was wondering what's the best way to convert it to MongoDB Strict format so that Splunk without having to use mongoexport or the REST API.

Thanks in advance.

Angel

Ian Bytchek

unread,
Aug 15, 2015, 3:48:44 AM8/15/15
to mongodb-user
Did you figure out how to do that?

an...@cultureamp.com

unread,
Feb 14, 2016, 9:12:41 PM2/14/16
to mongodb-user
Not yet...

AlainC

unread,
Feb 15, 2016, 11:34:48 AM2/15/16
to mongodb-user
You can try this :

--eval "print(tojson(db.runCommand({ serverStatus: 1 })).replace(/NumberLong\(([0-9]*)\)/gm,'$1').replace(/(\r\n|\n|\r|\s)/gm, '')))"

Not really proud of that, but at least it seem to work...
Reply all
Reply to author
Forward
0 new messages