json - 如何使用 MongoDB C++ 驱动程序将字符串转换为 BSON?

标签 json mongodb type-conversion bson

类似于 toString有没有办法可以将字符串转换为 BSON 对象?我需要使用 C++ 驱动程序删除文档,删除函数希望查询具有 BSON 对象。

最佳答案

使用此处的 fromjson 方法:

http://api.mongodb.org/cplusplus/1.5.4/namespacemongo.html#a4f542be0d0f9bad2d8cb32c3436026c2

BSONObj mongo::fromjson (   const string &  str  )  
Create a BSONObj from a JSON <http://www.json.org> string.

In addition to the JSON extensions extensions described here http://mongodb.onconfluence.com/display/DOCS/Mongo+Extended+JSON, this function accepts certain unquoted field names and allows single quotes to optionally be used when specifying field names and string values instead of double quotes. JSON unicode escape sequences (of the form ) are converted to utf8.

Exceptions: MsgAssertionException if parsing fails. The message included with this assertion includes a rough indication of where parsing failed.

关于json - 如何使用 MongoDB C++ 驱动程序将字符串转换为 BSON?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8785923/

相关文章:

mongodb - Sails with Mongo 中的 native 更新不适用于 ObjectId

mongodb - 在 Go 中将任何编码转换为 UTF 8

javascript - 将 CSV 转换为带有 header 的 JSON

c++ - 将字符串数组转换为 int 数组

sql - 在 postgresql 中使用变量作为键访问 json 对象

c# - 如何反序列化 JSON 字符串以便我可以在 C# 中循环它?

mongodb - 用 Mongoose 保存在 mongoDb 中,保存了意外的元素

c#反序列化json为List

sql - 发生冲突时,如果 PostgreSQL 中的 json 值不同则更新?

c++ - 处理 char 到 QString 转换中的 ASCII 字符