search

Home  >  Q&A  >  body text

mongodb c++驱动如何插入二进制数据?

我现在想给一个documents里边某一个字段设定二进制数据并且插入数据库。
我说的不是整个二进制文件。
想用一下方式传入数据
DBClientConnection oDB;
const std::string test =

        "{insert: \"test1\", documents: [{\"_id\" : 6,\"name\":\"vector6\",\"value\":0x00}]}";

bool runret = oDB.runCommand("wjhtest", mongo::fromjson(test), p2, 0);

结果出错了。我想问二进制的数据怎么插入呢。求例子

PHPzPHPz2804 days ago602

reply all(3)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 14:30:46

    You have to use a BSONObjBuilder

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 14:30:46

    The 0x00 you have here is actually a string, and what you want to insert is the value of 0x00, which is 0.
    So you need to convert your 0x00 into a string, i.e. "value":0

    reply
    0
  • 阿神

    阿神2017-04-17 14:30:46

    What if I want to insert a file at value? How to write it

    reply
    0
  • Cancelreply