BSONContent* BSONObj::getXpath(const std::string& xpath) const { __int32 posDot = xpath.find('.'); BSONContent* result = NULL; if (posDot == string::npos) { result = getContent(xpath); } else { std::string path = xpath.substr(0, posDot); result = getContent(path); if ((result != NULL) && (result->type() == BSON_TYPE)) { BSONContentBSON* bcontent = (BSONContentBSON*)result; BSONObj* inner = (BSONObj*)*bcontent; result = inner->getXpath(xpath.substr(posDot + 1)); } } if (result != NULL) { return result->clone(); } else { return NULL; } }
void BSONObj::add(std::string key, const BSONContent& val) { remove(key); BSONContent* content = val.clone(); _elements.insert(pair<std::string, BSONContent* >(key, content)); }