本文整理汇总了C++中mutablebson::Document::makeElementWithNewFieldName方法的典型用法代码示例。如果您正苦于以下问题:C++ Document::makeElementWithNewFieldName方法的具体用法?C++ Document::makeElementWithNewFieldName怎么用?C++ Document::makeElementWithNewFieldName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mutablebson::Document
的用法示例。
在下文中一共展示了Document::makeElementWithNewFieldName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createFromQuery
Status UpdateDriver::createFromQuery(const BSONObj& query, mutablebson::Document& doc) {
BSONObjIteratorSorted i(query);
while (i.more()) {
BSONElement e = i.next();
// TODO: get this logic/exclude-list from the query system?
if (e.fieldName()[0] == '$' || e.fieldNameStringData() == "_id")
continue;
if (e.type() == Object && e.embeddedObject().firstElementFieldName()[0] == '$') {
// we have something like { x : { $gt : 5 } }
// this can be a query piece
// or can be a dbref or something
int op = e.embeddedObject().firstElement().getGtLtOp();
if (op > 0) {
// This means this is a $gt type filter, so don't make it part of the new
// object.
continue;
}
if (mongoutils::str::equals(e.embeddedObject().firstElement().fieldName(),
"$not")) {
// A $not filter operator is not detected in getGtLtOp() and should not
// become part of the new object.
continue;
}
}
// Add to the field to doc after expanding and checking for conflicts.
FieldRef elemName;
const StringData& elemNameSD(e.fieldNameStringData());
elemName.parse(elemNameSD);
size_t pos;
mutablebson::Element* elemFound = NULL;
Status status = pathsupport::findLongestPrefix(elemName, doc.root(), &pos, elemFound);
// Not NonExistentPath, of OK, return
if (!(status.code() == ErrorCodes::NonExistentPath || status.isOK()))
return status;
status = pathsupport::createPathAt(elemName,
0,
doc.root(),
doc.makeElementWithNewFieldName(
elemName.getPart(elemName.numParts()-1),
e));
if (!status.isOK())
return status;
}
return Status::OK();
}