gpt4 book ai didi

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

转载 作者:IT老高 更新时间:2023-10-28 13:26:48 26 4
gpt4 key购买 nike

类似于 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com