mongodb c ++驱动程序和数组处理

问题描述

编辑-在此为感兴趣的参与者提供了一些帮助> https://developer.mongodb.com/community/forums/t/writting-query-for-array-in-c/7793/2

我正在学习如何在mongo中操作数组/对象...目前正在尝试按照本教程>

https://blog.mlab.com/2018/09/use-push-to-insert-elements-into-an-array/

主要>

> db.alphabet.insert({
      "_id": "22222","array": ['a','b','c','d','e','f','g','h','j']
  })
// We missed the 'i'!
// Let's add it in the position before the last element.
> db.alphabet.update(
      { "_id": "22222" },{
          $push: {
              array: {
              $each: ['i'],$position: -1
          }
      }
  })
// Check the results:
> db.alphabet.find({ "_id": "22222" })
{ "array" : [ "a","b","c","d","e","f","g","h","i","j" ] }v

我从这样的东西开始>

    auto replace = coll.update_one(make_document(kvp("_id",bsoncxx::oid("5f3289b7807200001f002b35"))),make_document(kvp("$push",make_document(
                                           kvp("arrayKeyTest","????????????????")

                                   ))));

但是卡住了其余的查询,数组...

我还想用类似以下的方法替换整个数组:


QVector<std::string> items= {"vfdsvds","vdsvsd","htrhjfgr","G243TYES"}
auto ar = bsoncxx::builder::basic::array{};

for(auto&e:items){
ar.append(e.c_str());
}

然后将ar作为某些键的值推入文档中...但是我迷路了...

任何帮助都会很棒。 TIA

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)