本文整理汇总了C++中MutableDocument类的典型用法代码示例。如果您正苦于以下问题:C++ MutableDocument类的具体用法?C++ MutableDocument怎么用?C++ MutableDocument使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MutableDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
boost::optional<Document> DocumentSourceRedact::redactObject() {
const Value expressionResult = _expression->evaluate(_variables.get());
if (expressionResult == keepVal) {
return _variables->getDocument(_currentId);
} else if (expressionResult == pruneVal) {
return boost::optional<Document>();
} else if (expressionResult == descendVal) {
const Document in = _variables->getDocument(_currentId);
MutableDocument out;
out.copyMetaDataFrom(in);
FieldIterator fields(in);
while (fields.more()) {
const Document::FieldPair field(fields.next());
// This changes CURRENT so don't read from _variables after this
const Value val = redactValue(field.second);
if (!val.missing()) {
out.addField(field.first, val);
}
}
return out.freeze();
} else {
uasserted(17053,
str::stream() << "$redact's expression should not return anything "
<< "aside from the variables $$KEEP, $$DESCEND, and "
<< "$$PRUNE, but returned "
<< expressionResult.toString());
}
}
示例2: if
boost::optional<Document> DocumentSourceRedact::redactObject(const Variables& in) {
const Value expressionResult = _expression->evaluate(in);
if (expressionResult == keepVal) {
return in.current.getDocument();
}
else if (expressionResult == pruneVal) {
return boost::optional<Document>();
}
else if (expressionResult == descendVal) {
MutableDocument out;
FieldIterator fields(in.current.getDocument());
while (fields.more()) {
const Document::FieldPair field(fields.next());
const Value val = redactValue(in, field.second);
if (!val.missing()) {
out.addField(field.first, val);
}
}
return out.freeze();
}
else {
uasserted(17053, str::stream() << "$redact's expression should not return anything "
<< "aside from the variables $$KEEP, $$DESCEND, and "
<< "$$PRUNE, but returned "
<< expressionResult.toString());
}
}
示例3: 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();
}
示例4: results
DocumentSource::GetNextResult DocumentSourceFacet::getNext() {
pExpCtx->checkForInterrupt();
if (_done) {
return GetNextResult::makeEOF();
}
vector<vector<Value>> results(_facets.size());
bool allPipelinesEOF = false;
while (!allPipelinesEOF) {
allPipelinesEOF = true; // Set this to false if any pipeline isn't EOF.
for (size_t facetId = 0; facetId < _facets.size(); ++facetId) {
const auto& pipeline = _facets[facetId].pipeline;
auto next = pipeline->getSources().back()->getNext();
for (; next.isAdvanced(); next = pipeline->getSources().back()->getNext()) {
results[facetId].emplace_back(next.releaseDocument());
}
allPipelinesEOF = allPipelinesEOF && next.isEOF();
}
}
MutableDocument resultDoc;
for (size_t facetId = 0; facetId < _facets.size(); ++facetId) {
resultDoc[_facets[facetId].name] = Value(std::move(results[facetId]));
}
_done = true; // We will only ever produce one result.
return resultDoc.freeze();
}
示例5: applyProjectionToOneField
bool applyProjectionToOneField(StringData field) const {
MutableDocument doc;
const FieldPath f{field};
doc.setNestedField(f, Value(1.0));
const Document transformedDoc = applyTransformation(doc.freeze());
return !transformedDoc.getNestedField(f).missing();
}
示例6: invariant
Value DocumentSourceGroup::serialize(bool explain) const {
MutableDocument insides;
// add the _id
if (_idFieldNames.empty()) {
invariant(_idExpressions.size() == 1);
insides["_id"] = _idExpressions[0]->serialize(explain);
}
else {
// decomposed document case
invariant(_idExpressions.size() == _idFieldNames.size());
MutableDocument md;
for (size_t i = 0; i < _idExpressions.size(); i++) {
md[_idFieldNames[i]] = _idExpressions[i]->serialize(explain);
}
insides["_id"] = md.freezeToValue();
}
// add the remaining fields
const size_t n = vFieldName.size();
for(size_t i = 0; i < n; ++i) {
intrusive_ptr<Accumulator> accum = vpAccumulatorFactory[i]();
insides[vFieldName[i]] =
Value(DOC(accum->getOpName() << vpExpression[i]->serialize(explain)));
}
if (_doingMerge) {
// This makes the output unparsable (with error) on pre 2.6 shards, but it will never
// be sent to old shards when this flag is true since they can't do a merge anyway.
insides["$doingMerge"] = Value(true);
}
return Value(DOC(getSourceName() << insides.freeze()));
}
示例7: Value
void ProjectionNode::serialize(boost::optional<ExplainOptions::Verbosity> explain,
MutableDocument* output) const {
// Determine the boolean value for projected fields in the explain output.
const bool projVal = !applyLeafProjectionToValue(Value(true)).missing();
// Always put "_id" first if it was projected (implicitly or explicitly).
if (_projectedFields.find("_id") != _projectedFields.end()) {
output->addField("_id", Value(projVal));
}
for (auto&& projectedField : _projectedFields) {
if (projectedField != "_id") {
output->addField(projectedField, Value(projVal));
}
}
for (auto&& field : _orderToProcessAdditionsAndChildren) {
auto childIt = _children.find(field);
if (childIt != _children.end()) {
MutableDocument subDoc;
childIt->second->serialize(explain, &subDoc);
output->addField(field, subDoc.freezeToValue());
} else {
invariant(_policies.computedFieldsPolicy == ComputedFieldsPolicy::kAllowComputedFields);
auto expressionIt = _expressions.find(field);
invariant(expressionIt != _expressions.end());
output->addField(field, expressionIt->second->serialize(static_cast<bool>(explain)));
}
}
}
示例8: serialize
Value DocumentSourceFacet::serialize(bool explain) const {
MutableDocument serialized;
for (auto&& facet : _facets) {
serialized[facet.name] =
Value(explain ? facet.pipeline->writeExplainOps() : facet.pipeline->serialize());
}
return Value(Document{{"$facet", serialized.freezeToValue()}});
}
示例9: getField
MutableValue MutableDocument::getNestedFieldHelper(const FieldPath& dottedField,
size_t level) {
if (level == dottedField.getPathLength()-1) {
return getField(dottedField.getFieldName(level));
}
else {
MutableDocument nested (getField(dottedField.getFieldName(level)));
return nested.getNestedFieldHelper(dottedField, level+1);
}
}
示例10: serialize
Document ExclusionNode::serialize() const {
MutableDocument output;
for (auto&& excludedField : _excludedFields) {
output.addField(excludedField, Value(false));
}
for (auto&& childPair : _children) {
output.addField(childPair.first, Value(childPair.second->serialize()));
}
return output.freeze();
}
示例11: Value
Value DocumentSourceCursor::serialize(boost::optional<ExplainOptions::Verbosity> verbosity) const {
// We never parse a DocumentSourceCursor, so we only serialize for explain.
if (!verbosity)
return Value();
invariant(_exec);
uassert(50660,
"Mismatch between verbosity passed to serialize() and expression context verbosity",
verbosity == pExpCtx->explain);
MutableDocument out;
out["query"] = Value(_query);
if (!_sort.isEmpty())
out["sort"] = Value(_sort);
if (_limit)
out["limit"] = Value(_limit->getLimit());
if (!_projection.isEmpty())
out["fields"] = Value(_projection);
BSONObjBuilder explainStatsBuilder;
{
auto opCtx = pExpCtx->opCtx;
auto lockMode = getLockModeForQuery(opCtx, _exec->nss());
AutoGetDb dbLock(opCtx, _exec->nss().db(), lockMode);
Lock::CollectionLock collLock(opCtx, _exec->nss(), lockMode);
auto collection =
dbLock.getDb() ? dbLock.getDb()->getCollection(opCtx, _exec->nss()) : nullptr;
Explain::explainStages(_exec.get(),
collection,
verbosity.get(),
_execStatus,
_winningPlanTrialStats.get(),
BSONObj(),
&explainStatsBuilder);
}
BSONObj explainStats = explainStatsBuilder.obj();
invariant(explainStats["queryPlanner"]);
out["queryPlanner"] = Value(explainStats["queryPlanner"]);
if (verbosity.get() >= ExplainOptions::Verbosity::kExecStats) {
invariant(explainStats["executionStats"]);
out["executionStats"] = Value(explainStats["executionStats"]);
}
return Value(DOC(getSourceName() << out.freezeToValue()));
}
示例12: Value
Value DocumentSourceCursor::serialize(bool explain) const {
// we never parse a documentSourceCursor, so we only serialize for explain
if (!explain)
return Value();
Status explainStatus(ErrorCodes::InternalError, "");
scoped_ptr<TypeExplain> plan;
{
Lock::DBRead lk(_ns);
Client::Context ctx(_ns, storageGlobalParams.dbpath, /*doVersion=*/false);
ClientCursorPin pin(_cursorId);
ClientCursor* cursor = pin.c();
uassert(17135, "Cursor deleted. Was the collection or database dropped?",
cursor);
Runner* runner = cursor->getRunner();
runner->restoreState();
TypeExplain* explainRaw;
explainStatus = runner->getExplainPlan(&explainRaw);
if (explainStatus.isOK())
plan.reset(explainRaw);
runner->saveState();
}
MutableDocument out;
out["query"] = Value(_query);
if (!_sort.isEmpty())
out["sort"] = Value(_sort);
if (_limit)
out["limit"] = Value(_limit->getLimit());
if (!_projection.isEmpty())
out["fields"] = Value(_projection);
if (explainStatus.isOK()) {
out["plan"] = Value(extractInfo(plan));
} else {
out["planError"] = Value(explainStatus.toString());
}
return out.freezeToValue();
}
示例13: getValue
Value AccumulatorAvg::getValue() const {
if (!pCtx->getInShard()) {
double avg = 0;
if (count)
avg = doubleTotal / static_cast<double>(count);
return Value::createDouble(avg);
}
MutableDocument out;
out.addField(subTotalName, Value::createDouble(doubleTotal));
out.addField(countName, Value::createLong(count));
return Value::createDocument(out.freeze());
}
示例14: Value
Value AccumulatorAvg::getValue(bool toBeMerged) const {
if (!toBeMerged) {
double avg = 0;
if (count)
avg = doubleTotal / static_cast<double>(count);
return Value(avg);
}
else {
MutableDocument out;
out.addField(subTotalName, Value(doubleTotal));
out.addField(countName, Value(count));
return Value(out.freeze());
}
}
示例15: 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();
}