本文整理汇总了C++中mutablebson::Element类的典型用法代码示例。如果您正苦于以下问题:C++ Element类的具体用法?C++ Element怎么用?C++ Element使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Element类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: Status
Status ModifierUnset::log(mutablebson::Element logRoot) const {
// We'd like to create an entry such as {$unset: {<fieldname>: 1}} under 'logRoot'.
// We start by creating the {$unset: ...} Element.
mutablebson::Document& doc = logRoot.getDocument();
mutablebson::Element unsetElement = doc.makeElementObject("$unset");
if (!unsetElement.ok()) {
return Status(ErrorCodes::InternalError, "cannot create log entry for $unset mod");
}
// Then we create the {<fieldname>: <value>} Element. Note that <fieldname> must be a
// dotted field, and not only the last part of that field. The rationale here is that
// somoene picking up this log entry -- e.g., a secondary -- must be capable of doing
// the same path find/creation that was done in the previous calls here.
mutablebson::Element logElement = doc.makeElementInt(_fieldRef.dottedField(), 1);
if (!logElement.ok()) {
return Status(ErrorCodes::InternalError, "cannot create log details for $unset mod");
}
// Now, we attach the {<fieldname>: `} Element under the {$unset: ...} one.
Status status = unsetElement.pushBack(logElement);
if (!status.isOK()) {
return status;
}
// And attach the result under the 'logRoot' Element provided.
return logRoot.pushBack(unsetElement);
}
开发者ID:328500920,项目名称:mongo,代码行数:28,代码来源:modifier_unset.cpp
示例2: Status
Status ModifierInc::log(mutablebson::Element logRoot) const {
// We'd like to create an entry such as {$set: {<fieldname>: <value>}} under 'logRoot'.
// We start by creating the {$set: ...} Element.
mutablebson::Document& doc = logRoot.getDocument();
mutablebson::Element setElement = doc.makeElementObject("$set");
if (!setElement.ok()) {
return Status(ErrorCodes::InternalError, "cannot append log entry for $set mod");
}
// Then we create the {<fieldname>: <value>} Element.
mutablebson::Element logElement = doc.makeElementSafeNum(
_fieldRef.dottedField(),
_preparedState->newValue);
if (!logElement.ok()) {
return Status(ErrorCodes::InternalError, "cannot append details for $set mod");
}
// Now, we attach the {<fieldname>: <value>} Element under the {$set: ...} one.
Status status = setElement.pushBack(logElement);
if (!status.isOK()) {
return status;
}
// And attach the result under the 'logRoot' Element provided.
return logRoot.pushBack(setElement);
}
开发者ID:4commerce-technologies-AG,项目名称:mongo,代码行数:28,代码来源:modifier_inc.cpp
示例3: Status
Status ModifierSet::log(mutablebson::Element logRoot) const {
// We'd like to create an entry such as {$set: {<fieldname>: <value>}} under 'logRoot'.
// We start by creating the {$set: ...} Element.
mutablebson::Document& doc = logRoot.getDocument();
mutablebson::Element setElement = doc.makeElementObject("$set");
if (!setElement.ok()) {
return Status(ErrorCodes::InternalError, "cannot create log entry for $set mod");
}
// Then we create the {<fieldname>: <value>} Element. Note that we log the mod with a
// dotted field, if it was applied over a dotted field. The rationale is that the
// secondary may be in a different state than the primary and thus make different
// decisions about creating the intermediate path in _fieldRef or not.
mutablebson::Element logElement = doc.makeElementWithNewFieldName(_fieldRef.dottedField(),
_val);
if (!logElement.ok()) {
return Status(ErrorCodes::InternalError, "cannot create details for $set mod");
}
// Now, we attach the {<fieldname>: <value>} Element under the {$set: ...} one.
Status status = setElement.pushBack(logElement);
if (!status.isOK()) {
return status;
}
// And attach the result under the 'logRoot' Element provided.
return logRoot.pushBack(setElement);
}
开发者ID:allanbank,项目名称:mongo,代码行数:29,代码来源:modifier_set.cpp
示例4: prepare
Status ModifierPush::prepare(mutablebson::Element root,
const StringData& matchedField,
ExecInfo* execInfo) {
_preparedState.reset(new PreparedState(&root.getDocument()));
// If we have a $-positional field, it is time to bind it to an actual field part.
if (_posDollar) {
if (matchedField.empty()) {
return Status(ErrorCodes::BadValue,
str::stream() << "The positional operator did not find the match "
"needed from the query. Unexpanded update: "
<< _fieldRef.dottedField());
}
_fieldRef.setPart(_posDollar, matchedField);
}
// Locate the field name in 'root'. Note that we may not have all the parts in the path
// in the doc -- which is fine. Our goal now is merely to reason about whether this mod
// apply is a noOp or whether is can be in place. The remainin path, if missing, will
// be created during the apply.
Status status = pathsupport::findLongestPrefix(_fieldRef,
root,
&_preparedState->idxFound,
&_preparedState->elemFound);
// FindLongestPrefix may say the path does not exist at all, which is fine here, or
// that the path was not viable or otherwise wrong, in which case, the mod cannot
// proceed.
if (status.code() == ErrorCodes::NonExistentPath) {
_preparedState->elemFound = root.getDocument().end();
}
else if (status.isOK()) {
const bool destExists = (_preparedState->idxFound == (_fieldRef.numParts()-1));
// If the path exists, we require the target field to be already an
// array.
if (destExists && _preparedState->elemFound.getType() != Array) {
mb::Element idElem = mb::findFirstChildNamed(root, "_id");
return Status(ErrorCodes::BadValue,
str::stream() << "The field '" << _fieldRef.dottedField() << "'"
<< " must be an array but is of type "
<< typeName(_preparedState->elemFound.getType())
<< " in document {" << idElem.toString() << "}");
}
}
else {
return status;
}
// We register interest in the field name. The driver needs this info to sort out if
// there is any conflict among mods.
execInfo->fieldRef[0] = &_fieldRef;
return Status::OK();
}
开发者ID:wjin,项目名称:mongo,代码行数:57,代码来源:modifier_push.cpp
示例5: addToSetsWithNewFieldName
Status LogBuilder::addToSetsWithNewFieldName(StringData name, const mutablebson::Element val) {
mutablebson::Element elemToSet = _logRoot.getDocument().makeElementWithNewFieldName(name, val);
if (!elemToSet.ok())
return Status(ErrorCodes::InternalError,
str::stream() << "Could not create new '" << name
<< "' element from existing element '"
<< val.getFieldName()
<< "' of type "
<< typeName(val.getType()));
return addToSets(elemToSet);
}
开发者ID:acmorrow,项目名称:mongo,代码行数:12,代码来源:log_builder.cpp
示例6: log
Status ModifierAddToSet::log(mb::Element logRoot) const {
// TODO: This is copied more or less identically from $push. As a result, it copies the
// behavior in $push that relies on 'apply' having been called unless this is a no-op.
// TODO We can log just a positional set in several cases. For now, let's just log the
// full resulting array.
// We'd like to create an entry such as {$set: {<fieldname>: [<resulting aray>]}} under
// 'logRoot'. We start by creating the {$set: ...} Element.
mb::Document& doc = logRoot.getDocument();
mb::Element setElement = doc.makeElementObject("$set");
if (!setElement.ok()) {
return Status(ErrorCodes::InternalError, "cannot create log entry for $addToSet mod");
}
// Then we create the {<fieldname>:[]} Element, that is, an empty array.
mb::Element logElement = doc.makeElementArray(_fieldRef.dottedField());
if (!logElement.ok()) {
return Status(ErrorCodes::InternalError, "cannot create details for $addToSet mod");
}
// Fill up the empty array.
mb::Element curr = _preparedState->elemFound.leftChild();
while (curr.ok()) {
dassert(curr.hasValue());
// We need to copy each array entry from the resulting document to the log
// document.
mb::Element currCopy = doc.makeElementWithNewFieldName(
StringData(),
curr.getValue());
if (!currCopy.ok()) {
return Status(ErrorCodes::InternalError, "could create copy element");
}
Status status = logElement.pushBack(currCopy);
if (!status.isOK()) {
return Status(ErrorCodes::BadValue, "could not append entry for $addToSet log");
}
curr = curr.rightSibling();
}
// Now, we attach the {<fieldname>: [<filled array>]} Element under the {$set: ...}
// one.
Status status = setElement.pushBack(logElement);
if (!status.isOK()) {
return status;
}
// And attach the result under the 'logRoot' Element provided.
return logRoot.pushBack(setElement);
}
开发者ID:4commerce-technologies-AG,项目名称:mongo,代码行数:53,代码来源:modifier_add_to_set.cpp
示例7: prepare
Status ModifierObjectReplace::prepare(mutablebson::Element root,
StringData matchedField,
ExecInfo* execInfo) {
_preparedState.reset(new PreparedState(&root.getDocument()));
// objectSize checked by binaryEqual (optimization)
BSONObj objOld = root.getDocument().getObject();
if (objOld.binaryEqual(_val)) {
_preparedState->noOp = true;
execInfo->noOp = true;
}
return Status::OK();
}
开发者ID:ChineseDr,项目名称:mongo,代码行数:14,代码来源:modifier_object_replace.cpp
示例8: prepare
Status ModifierObjectReplace::prepare(mutablebson::Element root,
const StringData& matchedField,
ExecInfo* execInfo) {
_preparedState.reset(new PreparedState(&root.getDocument()));
return Status::OK();
}
开发者ID:4commerce-technologies-AG,项目名称:mongo,代码行数:7,代码来源:modifier_object_replace.cpp
示例9: PreparedState
PreparedState(mutablebson::Element root)
: doc(root.getDocument())
, fromElemFound(doc.end())
, toIdxFound(0)
, toElemFound(doc.end())
, applyCalled(false){
}
开发者ID:3rf,项目名称:mongo,代码行数:7,代码来源:modifier_rename.cpp
示例10: prepare
Status ModifierCurrentDate::prepare(mutablebson::Element root,
StringData matchedField,
ExecInfo* execInfo) {
_preparedState.reset(new PreparedState(root.getDocument()));
// If we have a $-positional field, it is time to bind it to an actual field part.
if (_pathReplacementPosition) {
if (matchedField.empty()) {
return Status(ErrorCodes::BadValue,
str::stream() << "The positional operator did not find the match "
"needed from the query. Unexpanded update: "
<< _updatePath.dottedField());
}
_updatePath.setPart(_pathReplacementPosition, matchedField);
}
// Locate the field name in 'root'. Note that we may not have all the parts in the path
// in the doc -- which is fine. Our goal now is merely to reason about whether this mod
// apply is a noOp or whether is can be in place. The remaining path, if missing, will
// be created during the apply.
Status status = pathsupport::findLongestPrefix(_updatePath,
root,
&_preparedState->idxFound,
&_preparedState->elemFound);
// FindLongestPrefix may say the path does not exist at all, which is fine here, or
// that the path was not viable or otherwise wrong, in which case, the mod cannot
// proceed.
if (status.code() == ErrorCodes::NonExistentPath) {
_preparedState->elemFound = root.getDocument().end();
}
else if (!status.isOK()) {
return status;
}
// We register interest in the field name. The driver needs this info to sort out if
// there is any conflict among mods.
execInfo->fieldRef[0] = &_updatePath;
return Status::OK();
}
开发者ID:7segments,项目名称:mongo-1,代码行数:42,代码来源:modifier_current_date.cpp
示例11: PreparedState
Status ModifierUnset::prepare(mutablebson::Element root,
const StringData& matchedField,
ExecInfo* execInfo) {
_preparedState.reset(new PreparedState(&root.getDocument()));
// If we have a $-positional field, it is time to bind it to an actual field part.
if (_posDollar) {
if (matchedField.empty()) {
return Status(ErrorCodes::BadValue,
str::stream() << "The positional operator did not find the match "
"needed from the query. Unexpanded update: "
<< _fieldRef.dottedField());
}
_preparedState->boundDollar = matchedField.toString();
_fieldRef.setPart(_posDollar, _preparedState->boundDollar);
}
// Locate the field name in 'root'. Note that if we don't have the full path in the
// doc, there isn't anything to unset, really.
Status status = pathsupport::findLongestPrefix(_fieldRef,
root,
&_preparedState->idxFound,
&_preparedState->elemFound);
if (!status.isOK() ||
_preparedState->idxFound != (_fieldRef.numParts() -1)) {
execInfo->noOp = _preparedState->noOp = true;
execInfo->fieldRef[0] = &_fieldRef;
return Status::OK();
}
// If there is indeed something to unset, we register so, along with the interest in
// the field name. The driver needs this info to sort out if there is any conflict
// among mods.
execInfo->fieldRef[0] = &_fieldRef;
// The only way for an $unset to be inplace is for its target field to be the last one
// of the object. That is, it is always the right child on its paths. The current
// rationale is that there should be no holes in a BSONObj and, to be in place, no
// field boundaries must change.
//
// TODO:
// mutablebson::Element curr = _preparedState->elemFound;
// while (curr.ok()) {
// if (curr.rightSibling().ok()) {
// }
// curr = curr.parent();
// }
return Status::OK();
}
开发者ID:nevermindewe,项目名称:mongo,代码行数:53,代码来源:modifier_unset.cpp
示例12: getBSONForPrivileges
Status AuthorizationManager::getBSONForPrivileges(const PrivilegeVector& privileges,
mutablebson::Element resultArray) {
for (PrivilegeVector::const_iterator it = privileges.begin();
it != privileges.end(); ++it) {
std::string errmsg;
ParsedPrivilege privilege;
if (!ParsedPrivilege::privilegeToParsedPrivilege(*it, &privilege, &errmsg)) {
return Status(ErrorCodes::BadValue, errmsg);
}
resultArray.appendObject("privileges", privilege.toBSON());
}
return Status::OK();
}
开发者ID:AndrewCEmil,项目名称:mongo,代码行数:13,代码来源:authorization_manager.cpp
示例13: log
Status ModifierObjectReplace::log(mutablebson::Element logRoot) const {
// We'd like to create an entry such as {<object replacement>} under 'logRoot'.
mutablebson::Document& doc = logRoot.getDocument();
BSONObjIterator it(_val);
while (it.more()) {
BSONElement elem = it.next();
Status status = doc.root().appendElement(elem);
if (!status.isOK()) {
return status;
}
}
return Status::OK();
}
开发者ID:4commerce-technologies-AG,项目名称:mongo,代码行数:15,代码来源:modifier_object_replace.cpp
示例14: Status
Status AuthorizationManager::getBSONForRole(RoleGraph* graph,
const RoleName& roleName,
mutablebson::Element result) {
if (!graph->roleExists(roleName)) {
return Status(ErrorCodes::RoleNotFound,
mongoutils::str::stream() << roleName.getFullName() <<
"does not name an existing role");
}
std::string id = mongoutils::str::stream() << roleName.getDB() << "." << roleName.getRole();
result.appendString("_id", id);
result.appendString(ROLE_NAME_FIELD_NAME, roleName.getRole());
result.appendString(ROLE_DB_FIELD_NAME, roleName.getDB());
// Build privileges array
mutablebson::Element privilegesArrayElement =
result.getDocument().makeElementArray("privileges");
result.pushBack(privilegesArrayElement);
const PrivilegeVector& privileges = graph->getDirectPrivileges(roleName);
Status status = getBSONForPrivileges(privileges, privilegesArrayElement);
if (!status.isOK()) {
return status;
}
// Build roles array
mutablebson::Element rolesArrayElement = result.getDocument().makeElementArray("roles");
result.pushBack(rolesArrayElement);
for (RoleNameIterator roles = graph->getDirectSubordinates(roleName);
roles.more();
roles.next()) {
const RoleName& subRole = roles.get();
mutablebson::Element roleObj = result.getDocument().makeElementObject("");
roleObj.appendString(ROLE_NAME_FIELD_NAME, subRole.getRole());
roleObj.appendString(ROLE_DB_FIELD_NAME, subRole.getDB());
rolesArrayElement.pushBack(roleObj);
}
return Status::OK();
}
开发者ID:ramgtv,项目名称:mongo,代码行数:39,代码来源:authorization_manager.cpp
示例15: prepare
Status ModifierAddToSet::prepare(mb::Element root,
const StringData& matchedField,
ExecInfo* execInfo) {
_preparedState.reset(new PreparedState(root.getDocument()));
// If we have a $-positional field, it is time to bind it to an actual field part.
if (_posDollar) {
if (matchedField.empty()) {
return Status(ErrorCodes::BadValue, "matched field not provided");
}
_preparedState->boundDollar = matchedField.toString();
_fieldRef.setPart(_posDollar, _preparedState->boundDollar);
}
// Locate the field name in 'root'.
Status status = pathsupport::findLongestPrefix(_fieldRef,
root,
&_preparedState->idxFound,
&_preparedState->elemFound);
// FindLongestPrefix may say the path does not exist at all, which is fine here, or
// that the path was not viable or otherwise wrong, in which case, the mod cannot
// proceed.
if (status.code() == ErrorCodes::NonExistentPath) {
_preparedState->elemFound = root.getDocument().end();
} else if (!status.isOK()) {
return status;
}
// We register interest in the field name. The driver needs this info to sort out if
// there is any conflict among mods.
execInfo->fieldRef[0] = &_fieldRef;
//
// in-place and no-op logic
//
// If the field path is not fully present, then this mod cannot be in place, nor is a
// noOp.
if (!_preparedState->elemFound.ok() ||
_preparedState->idxFound < static_cast<int32_t>(_fieldRef.numParts() - 1)) {
// If no target element exists, we will simply be creating a new array.
_preparedState->addAll = true;
return Status::OK();
}
// This operation only applies to arrays
if (_preparedState->elemFound.getType() != mongo::Array)
return Status(
ErrorCodes::BadValue,
"Cannot apply $addToSet to a non-array value");
// If the array is empty, then we don't need to check anything: all of the values are
// going to be added.
if (!_preparedState->elemFound.hasChildren()) {
_preparedState->addAll = true;
return Status::OK();
}
// For each value in the $each clause, compare it against the values in the array. If
// the element is not present, record it as one to add.
mb::Element eachIter = _val.leftChild();
while (eachIter.ok()) {
mb::Element where = mb::findElement(
_preparedState->elemFound.leftChild(),
mb::woEqualTo(eachIter, false));
if (!where.ok()) {
// The element was not found. Record the element from $each as one to be added.
_preparedState->elementsToAdd.push_back(eachIter);
}
eachIter = eachIter.rightSibling();
}
// If we didn't find any elements to add, then this is a no-op, and therefore in place.
if (_preparedState->elementsToAdd.empty()) {
_preparedState->noOp = execInfo->noOp = true;
execInfo->inPlace = true;
}
return Status::OK();
}
开发者ID:4commerce-technologies-AG,项目名称:mongo,代码行数:82,代码来源:modifier_add_to_set.cpp
示例16: prepare
Status ModifierInc::prepare(mutablebson::Element root,
const StringData& matchedField,
ExecInfo* execInfo) {
_preparedState.reset(new PreparedState(root.getDocument()));
// If we have a $-positional field, it is time to bind it to an actual field part.
if (_posDollar) {
if (matchedField.empty()) {
return Status(ErrorCodes::BadValue, "matched field not provided");
}
_preparedState->boundDollar = matchedField.toString();
_fieldRef.setPart(_posDollar, _preparedState->boundDollar);
}
// Locate the field name in 'root'. Note that we may not have all the parts in the path
// in the doc -- which is fine. Our goal now is merely to reason about whether this mod
// apply is a noOp or whether is can be in place. The remaining path, if missing, will
// be created during the apply.
Status status = pathsupport::findLongestPrefix(_fieldRef,
root,
&_preparedState->idxFound,
&_preparedState->elemFound);
// FindLongestPrefix may say the path does not exist at all, which is fine here, or
// that the path was not viable or otherwise wrong, in which case, the mod cannot
// proceed.
if (status.code() == ErrorCodes::NonExistentPath) {
_preparedState->elemFound = root.getDocument().end();
}
else if (!status.isOK()) {
return status;
}
// We register interest in the field name. The driver needs this info to sort out if
// there is any conflict among mods.
execInfo->fieldRef[0] = &_fieldRef;
// Capture the value we are going to write. At this point, there may not be a value
// against which to operate, so the result will be simply _val.
_preparedState->newValue = _val;
//
// in-place and no-op logic
//
// If the field path is not fully present, then this mod cannot be in place, nor is a
// noOp.
if (!_preparedState->elemFound.ok() ||
_preparedState->idxFound < static_cast<int32_t>(_fieldRef.numParts() - 1)) {
return Status::OK();
}
// If the value being $inc'ed is the same as the one already in the doc, than this is a
// noOp.
if (!_preparedState->elemFound.isNumeric())
return Status(ErrorCodes::BadValue,
"invalid attempt to increment a non-numeric field");
const SafeNum currentValue = _preparedState->elemFound.getValueSafeNum();
// Update newValue w.r.t to the current value of the found element.
_preparedState->newValue += currentValue;
// If the result of the addition is invalid, we must return an error.
if (!_preparedState->newValue.isValid())
return Status(ErrorCodes::BadValue,
"Failed to increment current value");
// If the values are identical (same type, same value), then this is a no-op, and
// therefore in-place as well.
if (_preparedState->newValue.isIdentical(currentValue)) {
_preparedState->noOp = execInfo->noOp = true;
_preparedState->inPlace = execInfo->inPlace = true;
return Status::OK();
}
// If the types are the same, this can be done in place.
//
// TODO: Potentially, cases where $inc results in a mixed type of the same size could
// be in-place as well, but we don't currently handle them.
if (_preparedState->newValue.type() == currentValue.type()) {
_preparedState->inPlace = execInfo->inPlace = true;
}
return Status::OK();
}
开发者ID:4commerce-technologies-AG,项目名称:mongo,代码行数:86,代码来源:modifier_inc.cpp
示例17: prepare
Status ModifierInc::prepare(mutablebson::Element root,
const StringData& matchedField,
ExecInfo* execInfo) {
_preparedState.reset(new PreparedState(root.getDocument()));
// If we have a $-positional field, it is time to bind it to an actual field part.
if (_posDollar) {
if (matchedField.empty()) {
return Status(ErrorCodes::BadValue,
str::stream() << "The positional operator did not find the match "
"needed from the query. Unexpanded update: "
<< _fieldRef.dottedField());
}
_fieldRef.setPart(_posDollar, matchedField);
}
// Locate the field name in 'root'. Note that we may not have all the parts in the path
// in the doc -- which is fine. Our goal now is merely to reason about whether this mod
// apply is a noOp or whether is can be in place. The remaining path, if missing, will
// be created during the apply.
Status status = pathsupport::findLongestPrefix(_fieldRef,
root,
&_preparedState->idxFound,
&_preparedState->elemFound);
// FindLongestPrefix may say the path does not exist at all, which is fine here, or
// that the path was not viable or otherwise wrong, in which case, the mod cannot
// proceed.
if (status.code() == ErrorCodes::NonExistentPath) {
_preparedState->elemFound = root.getDocument().end();
}
else if (!status.isOK()) {
return status;
}
// We register interest in the field name. The driver needs this info to sort out if
// there is any conflict among mods.
execInfo->fieldRef[0] = &_fieldRef;
// Capture the value we are going to write. At this point, there may not be a value
// against which to operate, so the result will be simply _val.
_preparedState->newValue = _val;
//
// in-place and no-op logic
//
// If the field path is not fully present, then this mod cannot be in place, nor is a
// noOp.
if (!_preparedState->elemFound.ok() ||
_preparedState->idxFound < (_fieldRef.numParts() - 1)) {
// For multiplication, we treat ops against missing as yielding zero. We take
// advantage here of the promotion rules for SafeNum; the expression below will
// always yield a zero of the same type of operand that the user provided
// (e.g. double).
if (_mode == MODE_MUL)
_preparedState->newValue *= SafeNum(static_cast<int>(0));
return Status::OK();
}
// If the value being $inc'ed is the same as the one already in the doc, than this is a
// noOp.
if (!_preparedState->elemFound.isNumeric()) {
mb::Element idElem = mb::findFirstChildNamed(root, "_id");
return Status(
ErrorCodes::BadValue,
str::stream() << "Cannot apply "
<< (_mode == MODE_INC ? "$inc" : "$mul")
<< " to a value of non-numeric type. {"
<< idElem.toString()
<< "} has the field '" << _preparedState->elemFound.getFieldName()
<< "' of non-numeric type "
<< typeName(_preparedState->elemFound.getType()));
}
const SafeNum currentValue = _preparedState->elemFound.getValueSafeNum();
// Update newValue w.r.t to the current value of the found element.
if (_mode == MODE_INC)
_preparedState->newValue += currentValue;
else
_preparedState->newValue *= currentValue;
// If the result of the addition is invalid, we must return an error.
if (!_preparedState->newValue.isValid()) {
mb::Element idElem = mb::findFirstChildNamed(root, "_id");
return Status(ErrorCodes::BadValue,
str::stream() << "Failed to apply $inc operations to current value ("
<< currentValue.debugString() << ") for document {"
<< idElem.toString() << "}");
}
// If the values are identical (same type, same value), then this is a no-op.
if (_preparedState->newValue.isIdentical(currentValue)) {
_preparedState->noOp = execInfo->noOp = true;
return Status::OK();
}
return Status::OK();
//.........这里部分代码省略.........
开发者ID:DanilSerd,项目名称:mongo,代码行数:101,代码来源:modifier_inc.cpp
示例18: PreparedState
Status ModifierPush::prepare(mutablebson::Element root,
const StringData& matchedField,
ExecInfo* execInfo) {
_preparedState.reset(new PreparedState(&root.getDocument()));
// If we have a $-positional field, it is time to bind it to an actual field part.
if (_posDollar) {
if (matchedField.empty()) {
return Status(ErrorCodes::BadValue, "matched field not provided");
}
_preparedState->boundDollar = matchedField.toString();
_fieldRef.setPart(_posDollar, _preparedState->boundDollar);
}
// Locate the field name in 'root'. Note that we may not have all the parts in the path
// in the doc -- which is fine. Our goal now is merely to reason about whether this mod
// apply is a noOp or whether is can be in place. The remainin path, if missing, will
// be created during the apply.
Status status = pathsupport::findLongestPrefix(_fieldRef,
root,
&_preparedState->idxFound,
&_preparedState->elemFound);
// FindLongestPrefix may say the path does not exist at all, which is fine here, or
// that the path was not viable or otherwise wrong, in which case, the mod cannot
// proceed.
if (status.code() == ErrorCodes::NonExistentPath) {
_preparedState->elemFound = root.getDocument().end();
}
else if (status.isOK()) {
const bool destExists = (_preparedState->idxFound == (_fieldRef.numParts()-1));
// If the path exists, we require the target field to be already an
// array.
if (destExists && _preparedState->elemFound.getType() != Array) {
return Status(ErrorCodes::BadValue, "can only $push into arrays");
}
// If the $sort clause is being used, we require all the items in the array to be
// objects themselves (as opposed to base types). This is a temporary restriction
// that can be lifted once we support full sort semantics in $push.
if (_sortPresent && destExists) {
mutablebson::Element curr = _preparedState->elemFound.leftChild();
while (curr.ok()) {
if (curr.getType() != Object) {
return Status(ErrorCodes::BadValue,
"$push with sort requires object arrays");
}
curr = curr.rightSibling();
}
}
}
else {
return status;
}
// We register interest in the field name. The driver needs this info to sort out if
// there is any conflict among mods.
execInfo->fieldRef[0] = &_fieldRef;
return Status::OK();
}
开发者ID:duraidxg,项目名称:mongo,代码行数:65,代码来源:modifier_push.cpp
示例19: prepare
Status ModifierBit::prepare(mutablebson::Element root,
StringData matchedField,
ExecInfo* execInfo) {
_preparedState.reset(new PreparedState(root.getDocument()));
// If we have a $-positional field, it is time to bind it to an actual field part.
if (_posDollar) {
if (matchedField.empty()) {
return Status(ErrorCodes::BadValue,
str::stream() << "The positional operator did not find the match "
"needed from the query. Unexpanded update: "
<< _fieldRef.dottedField());
}
_fieldRef.setPart(_posDollar, matchedField);
}
// Locate the field name in 'root'.
Status status = pathsupport::findLongestPrefix(
_fieldRef, root, &_preparedState->idxFound, &_preparedState->elemFound);
// FindLongestPrefix may say the path does not exist at all, which is fine here, or
// that the path was not viable or otherwise wrong, in which case, the mod cannot
// proceed.
if (status.code() == ErrorCodes::NonExistentPath) {
_preparedState->elemFound = root.getDocument().end();
} else if (!status.isOK()) {
return status;
}
// We register interest in the field name. The driver needs this info to sort out if
// there is any conflict among mods.
execInfo->fieldRef[0] = &_fieldRef;
//
// in-place and no-op logic
//
// If the field path is not fully present, then this mod cannot be in place, nor is a
// noOp.
if (!_preparedState->elemFound.ok() || _preparedState->idxFound < (_fieldRef.numParts() - 1)) {
// If no target element exists, the value we will write is the result of applying
// the operation to a zero-initialized integer element.
_preparedState->newValue = apply(SafeNum(static_cast<int>(0)));
return Status::OK();
}
if (!_preparedState->elemFound.isIntegral()) {
mb::Element idElem = mb::findElementNamed(root.leftChild(), "_id");
return Status(ErrorCodes::BadValue,
str::stream() << "Cannot apply $bit to a value of non-integral type."
<< idElem.toString() << " has the field "
<< _preparedState->elemFound.getFieldName()
<< " of non-integer type "
<< typeName(_preparedState->elemFound.getType()));
}
const SafeNum currentValue = _preparedState->elemFound.getValueSafeNum();
// Apply the op over the existing value and the mod value, and capture the result.
_preparedState->newValue = apply(currentValue);
if (!_preparedState->newValue.isValid()) {
// TODO: Include list of ops, if that is easy, at some future point.
return Status(ErrorCodes::BadValue,
str::stream() << "Failed to apply $bit operations to current value: "
<< currentValue.debugString());
}
// If the values are identical (same type, same value), then this is a no-op.
if (_preparedState->newValue.isIdentical(currentValue)) {
_preparedState->noOp = execInfo->
|
请发表评论