本文整理汇总了C++中MutableDocument::setField方法的典型用法代码示例。如果您正苦于以下问题:C++ MutableDocument::setField方法的具体用法?C++ MutableDocument::setField怎么用?C++ MutableDocument::setField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MutableDocument
的用法示例。
在下文中一共展示了MutableDocument::setField方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: serialize
Value DocumentSourceGeoNear::serialize(bool explain) const {
MutableDocument result;
if (coordsIsArray) {
result.setField("near", Value(BSONArray(coords)));
} else {
result.setField("near", Value(coords));
}
// not in buildGeoNearCmd
result.setField("distanceField", Value(distanceField->fullPath()));
result.setField("limit", Value(limit));
if (maxDistance > 0)
result.setField("maxDistance", Value(maxDistance));
if (minDistance > 0)
result.setField("minDistance", Value(minDistance));
result.setField("query", Value(query));
result.setField("spherical", Value(spherical));
result.setField("distanceMultiplier", Value(distanceMultiplier));
if (includeLocs)
result.setField("includeLocs", Value(includeLocs->fullPath()));
return Value(DOC(getSourceName() << result.freeze()));
}
示例2: sortKeyPattern
Document DocumentSourceSort::sortKeyPattern(SortKeySerialization serializationMode) const {
MutableDocument keyObj;
const size_t n = _sortPattern.size();
for (size_t i = 0; i < n; ++i) {
if (_sortPattern[i].fieldPath) {
// Append a named integer based on whether the sort is ascending/descending.
keyObj.setField(_sortPattern[i].fieldPath->fullPath(),
Value(_sortPattern[i].isAscending ? 1 : -1));
} else {
// Sorting by an expression, use a made up field name.
auto computedFieldName = string(str::stream() << "$computed" << i);
switch (serializationMode) {
case SortKeySerialization::kForExplain:
case SortKeySerialization::kForPipelineSerialization: {
const bool isExplain = (serializationMode == SortKeySerialization::kForExplain);
keyObj[computedFieldName] = _sortPattern[i].expression->serialize(isExplain);
break;
}
case SortKeySerialization::kForSortKeyMerging: {
// We need to be able to tell which direction the sort is. Expression sorts are
// always descending.
keyObj[computedFieldName] = Value(-1);
break;
}
}
}
}
return keyObj.freeze();
}
示例3: serializeSortKey
Document DocumentSourceSort::serializeSortKey() const {
MutableDocument keyObj;
// add the key fields
const size_t n = vSortKey.size();
for(size_t i = 0; i < n; ++i) {
// get the field name out of each ExpressionFieldPath
const FieldPath& withVariable = vSortKey[i]->getFieldPath();
verify(withVariable.getPathLength() > 1);
verify(withVariable.getFieldName(0) == "ROOT");
const string fieldPath = withVariable.tail().getPath(false);
// append a named integer based on the sort order
keyObj.setField(fieldPath, Value(vAscending[i] ? 1 : -1));
}
return keyObj.freeze();
}
示例4: serializeSortKey
Document DocumentSourceSort::serializeSortKey(bool explain) const {
MutableDocument keyObj;
// add the key fields
const size_t n = vSortKey.size();
for (size_t i = 0; i < n; ++i) {
if (ExpressionFieldPath* efp = dynamic_cast<ExpressionFieldPath*>(vSortKey[i].get())) {
// ExpressionFieldPath gets special syntax that includes direction
const FieldPath& withVariable = efp->getFieldPath();
verify(withVariable.getPathLength() > 1);
verify(withVariable.getFieldName(0) == "ROOT");
const string fieldPath = withVariable.tail().fullPath();
// append a named integer based on the sort order
keyObj.setField(fieldPath, Value(vAscending[i] ? 1 : -1));
} else {
// other expressions use a made-up field name
keyObj[string(str::stream() << "$computed" << i)] = vSortKey[i]->serialize(explain);
}
}
return keyObj.freeze();
}