cvsdave
cvsdave

Reputation: 1606

BASH BSON parser

We need to do some queries of a Mongo DB from BASH shell scripts. Using eval and Mongo's printjson() gives me text output, but it needs to be parsed. Using other scripting languages (Python, Ruby, Erlang, etc) is not an option.

I looked at JSON.sh ( a BASH script lib JSON parser: https://github.com/rcrowley/json.sh ) and it appears to be close to a solution other than the issue that it does not recognize BSON-but-not-JSON data types. Before I try to mod it to recognize BSON data types, is anyone aware of an existing solution?

Thanks.

10/11 Below Stennie notes that I have received an answer in the MongoDB User group, and provides a URL. The answer is very nice and complete, and begins, "MongoDB actually uses what we call Mongo Extended JSON which differs a bit from the vanilla JSON standard..." so I will have to modify the parser. Thanks to all.

Upvotes: 1

Views: 1209

Answers (1)

Kay
Kay

Reputation: 3012

Do you perhaps want to use tojson() rather than printjson() and loop through the result of tojson() to parse the fields?

Upvotes: 2

Related Questions