Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在mongo-c-driver或mongo cxx驱动程序中升级文档后如何获取“\u id”?_C++_C_Mongodb_Mongo C Driver_Mongo Cxx Driver - Fatal编程技术网

C++ 在mongo-c-driver或mongo cxx驱动程序中升级文档后如何获取“\u id”?

C++ 在mongo-c-driver或mongo cxx驱动程序中升级文档后如何获取“\u id”?,c++,c,mongodb,mongo-c-driver,mongo-cxx-driver,C++,C,Mongodb,Mongo C Driver,Mongo Cxx Driver,在mongo-c-driver或mongo cxx驱动程序中升级文档后如何获取\u id 下面的代码片段来自mongo shell,它显示了WriteResult最后一行的\u id字段 db.coll.update( { item: "ZZZ135" }, { item: "ZZZ135", stock: 5, tags: [ "database" ] }, {upsert: true}

在mongo-c-driver或mongo cxx驱动程序中升级文档后如何获取
\u id

下面的代码片段来自mongo shell,它显示了
WriteResult
最后一行的
\u id
字段

db.coll.update(
               { item: "ZZZ135" },
               {  item: "ZZZ135",  stock: 5,  tags: [ "database" ] },
               {upsert: true} 
              )

WriteResult({
    "nMatched" : 0,
    "nUpserted" : 1,
    "nModified" : 0,
    "_id" : ObjectId("54455f33b247e073d7161b32")
})

在mongo C驱动程序中,您可以使用
bson\t*reply
在以下位置接收返回的
\u id

<> > C++中的等价项是<代码> bSONOB**FIG/<代码>:

bool mongoc_collection_command_simple (
      mongoc_collection_t       *collection,
      const bson_t              *command,
      const mongoc_read_prefs_t *read_prefs,
      bson_t                    *reply,
      bson_error_t              *error
)
bool mongo::DBClientWithCommands::simpleCommand (
        const std::string &     dbname,
        BSONObj *   info,
        const std::string &     command 
)