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

6
toString类似,我们是否可以将字符串转换为BSON对象?我需要使用C++驱动程序删除文档,但是remove函数需要查询具有BSON对象。
1个回答

8
使用此处找到的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.

除了在这里描述的JSON扩展 http://mongodb.onconfluence.com/display/DOCS/Mongo+Extended+JSON,此函数还接受某些未引用的字段名,并允许在指定字段名和字符串值时可选使用单引号而不是双引号。 JSON unicode 转义序列 (形式为)会转换为utf8。
异常: 如果解析失败,则 MsgAssertionException 将被抛出。此断言所包含的消息包括解析失败的位置的粗略指示。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接