根据需求,想在原有的BSONObj变量中增加一个域,查找到了函数
int addFields(BSONObj& from, std::set<std::string>& fields);
该函数的解释:如果没有指定域,则添加域,返回域ID ,也得到了该函数的应用方法,但是总是出错,查了好多网上的资料都没有对该错误做出解释,也没有对该函数的正确用法与注意事项做出说明。
所以只能找到曲线救国的方法
一个已有的BSONObj变量p,增加阈值“content” 并设置内容为strContent
如下:
BSONObjBuilder tempJson;
tempJson.appendElements(p);
tempJson.append("content",strContent);
p = tempJson.obj();
tempJson.appendElements(p);
tempJson.append("content",strContent);
p = tempJson.obj();
这样就可以满足需求。