MongoDB bsoncxx 在解析具有 int64_t 值的 json 文档时崩溃

MongoDB bsoncxx crash parsing a json document with int64_t value

我正在使用 Bson 库函数 ToJson() 在 C# 中生成一个 json 文档。文档开头为:

{ “密钥”:NumberLong(“2053249000001086”), ...

我正在使用 bsoncxx 驱动程序在 C++ DLL 中解析此文档。 此行抛出异常: '''bsoncxx::from_json(TheJsonDocument).view()'''

with What =“在“u”处出现解析错误,位置 11:“SPECIAL_EXPECTED”:无法解析 JSON 文档”

换句话说:不支持 NumberLong() 标签。 我目前使用的解决方法是导出一个字符串,并在 DLL 中使用 atoll() 读取它。

有更好的主意吗?

您生成的扩展json无效。正确的拼写是

{"$numberLong": <64-bit signed integer as a string>}

参见https://github.com/mongodb/specifications/blob/master/source/extended-json.rst#conversion-table

您需要修复生产方以生产正确的扩展 json。