本文介绍了BASH BSON解析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们需要从BASH Shell脚本中查询Mongo DB.使用eval和Mongo的printjson()给我文本输出,但是需要对其进行解析.不能使用其他脚本语言(Python,Ruby,Erlang等).

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.

我查看了JSON.sh(BASH脚本库JSON解析器: https://github.com/rcrowley/json.sh ),除了它无法识别BSON-not-not-JSON数据类型的问题外,它似乎与解决方案很接近.在尝试修改它以识别BSON数据类型之前,有人知道现有的解决方案吗?

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?

谢谢.

10/11 Stennie在下面指出,我在MongoDB用户组中收到了一个答案,并提供了一个URL.答案是非常完整的,并且开始说:"MongoDB实际上使用了我们称为Mongo Extended JSON的东西,它与原始JSON标准有所不同...",因此我将不得不修改解析器.谢谢大家.

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.

推荐答案

您是否要使用tojson()而不是printjson()并遍历tojson()的结果来解析字段?

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

这篇关于BASH BSON解析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 02:50