summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2013-09-30 18:53:53 -0400
committerMathias Stearn <mathias@10gen.com>2013-10-11 13:00:53 -0400
commit257292ade0ce14ca4785ca9889b0579be8a3e36b (patch)
treef112929c9f8d9f8ccb23d2bd82fc6bd77694c22c
parente76e27acacd2e2665e741be3cb58b4071f6616a4 (diff)
downloadmongo-257292ade0ce14ca4785ca9889b0579be8a3e36b.tar.gz
Don't require a pointer to BSONElement in pipeline parsing.
Prevents use of rvalues among other annoying issues.
-rw-r--r--src/mongo/db/pipeline/document_source.h32
-rw-r--r--src/mongo/db/pipeline/document_source_bson_array.cpp14
-rw-r--r--src/mongo/db/pipeline/document_source_command_shards.cpp2
-rw-r--r--src/mongo/db/pipeline/document_source_geo_near.cpp4
-rw-r--r--src/mongo/db/pipeline/document_source_group.cpp19
-rw-r--r--src/mongo/db/pipeline/document_source_limit.cpp8
-rw-r--r--src/mongo/db/pipeline/document_source_match.cpp13
-rw-r--r--src/mongo/db/pipeline/document_source_merge_cursors.cpp8
-rw-r--r--src/mongo/db/pipeline/document_source_out.cpp8
-rw-r--r--src/mongo/db/pipeline/document_source_project.cpp8
-rw-r--r--src/mongo/db/pipeline/document_source_redact.cpp6
-rw-r--r--src/mongo/db/pipeline/document_source_skip.cpp8
-rw-r--r--src/mongo/db/pipeline/document_source_sort.cpp8
-rw-r--r--src/mongo/db/pipeline/document_source_unwind.cpp8
-rw-r--r--src/mongo/db/pipeline/expression.cpp12
-rw-r--r--src/mongo/db/pipeline/expression.h7
-rw-r--r--src/mongo/db/pipeline/pipeline.cpp4
-rw-r--r--src/mongo/dbtests/documentsourcetests.cpp24
-rw-r--r--src/mongo/dbtests/expressiontests.cpp8
19 files changed, 94 insertions, 107 deletions
diff --git a/src/mongo/db/pipeline/document_source.h b/src/mongo/db/pipeline/document_source.h
index b64d861f391..f68c62357dc 100644
--- a/src/mongo/db/pipeline/document_source.h
+++ b/src/mongo/db/pipeline/document_source.h
@@ -302,16 +302,17 @@ namespace mongo {
elements that appear after these documents must not be read until
this source is exhausted.
- @param pBsonElement the BSON array to treat as a document source
+ @param array the BSON array to treat as a document source
@param pExpCtx the expression context for the pipeline
@returns the newly created document source
*/
static intrusive_ptr<DocumentSourceBsonArray> create(
- BSONElement *pBsonElement,
+ const BSONObj& array,
const intrusive_ptr<ExpressionContext> &pExpCtx);
private:
- DocumentSourceBsonArray(BSONElement *pBsonElement,
+ DocumentSourceBsonArray(
+ const BSONObj& embeddedArray,
const intrusive_ptr<ExpressionContext> &pExpCtx);
BSONObj embeddedObject;
@@ -584,7 +585,7 @@ namespace mongo {
@returns the grouping DocumentSource
*/
static intrusive_ptr<DocumentSource> createFromBson(
- BSONElement *pBsonElement,
+ BSONElement elem,
const intrusive_ptr<ExpressionContext> &pExpCtx);
// Virtuals for SplittableDocumentSource
@@ -666,7 +667,7 @@ namespace mongo {
@returns the filter
*/
static intrusive_ptr<DocumentSource> createFromBson(
- BSONElement *pBsonElement,
+ BSONElement elem,
const intrusive_ptr<ExpressionContext> &pCtx);
/**
@@ -708,7 +709,7 @@ namespace mongo {
virtual bool isValidInitialSource() const { return true; }
static intrusive_ptr<DocumentSource> createFromBson(
- BSONElement *pBsonElement,
+ BSONElement elem,
const intrusive_ptr<ExpressionContext> &pExpCtx);
static intrusive_ptr<DocumentSource> create(
@@ -768,7 +769,7 @@ namespace mongo {
@returns the newly created document source
*/
static intrusive_ptr<DocumentSource> createFromBson(
- BSONElement *pBsonElement,
+ BSONElement elem,
const intrusive_ptr<ExpressionContext> &pExpCtx);
static const char outName[];
@@ -811,7 +812,7 @@ namespace mongo {
@returns the created projection
*/
static intrusive_ptr<DocumentSource> createFromBson(
- BSONElement *pBsonElement,
+ BSONElement elem,
const intrusive_ptr<ExpressionContext> &pExpCtx);
static const char projectName[];
@@ -842,8 +843,9 @@ namespace mongo {
static const char redactName[];
- static intrusive_ptr<DocumentSource> createFromBson(BSONElement* bsonElement,
- const intrusive_ptr<ExpressionContext>& expCtx);
+ static intrusive_ptr<DocumentSource> createFromBson(
+ BSONElement elem,
+ const intrusive_ptr<ExpressionContext>& expCtx);
virtual Value serialize(bool explain = false) const;
@@ -902,7 +904,7 @@ namespace mongo {
@returns the grouping DocumentSource
*/
static intrusive_ptr<DocumentSource> createFromBson(
- BSONElement *pBsonElement,
+ BSONElement elem,
const intrusive_ptr<ExpressionContext> &pExpCtx);
/// Create a DocumentSourceSort with a given sort and (optional) limit
@@ -1007,7 +1009,7 @@ namespace mongo {
@returns the grouping DocumentSource
*/
static intrusive_ptr<DocumentSource> createFromBson(
- BSONElement *pBsonElement,
+ BSONElement elem,
const intrusive_ptr<ExpressionContext> &pExpCtx);
static const char limitName[];
@@ -1062,7 +1064,7 @@ namespace mongo {
@returns the grouping DocumentSource
*/
static intrusive_ptr<DocumentSource> createFromBson(
- BSONElement *pBsonElement,
+ BSONElement elem,
const intrusive_ptr<ExpressionContext> &pExpCtx);
static const char skipName[];
@@ -1096,7 +1098,7 @@ namespace mongo {
@returns the created projection
*/
static intrusive_ptr<DocumentSource> createFromBson(
- BSONElement *pBsonElement,
+ BSONElement elem,
const intrusive_ptr<ExpressionContext> &pExpCtx);
static const char unwindName[];
@@ -1131,7 +1133,7 @@ namespace mongo {
virtual intrusive_ptr<DocumentSource> getRouterSource();
static intrusive_ptr<DocumentSource> createFromBson(
- BSONElement *pBsonElement,
+ BSONElement elem,
const intrusive_ptr<ExpressionContext> &pCtx);
static char geoNearName[];
diff --git a/src/mongo/db/pipeline/document_source_bson_array.cpp b/src/mongo/db/pipeline/document_source_bson_array.cpp
index cb5139a8b49..47c14f22570 100644
--- a/src/mongo/db/pipeline/document_source_bson_array.cpp
+++ b/src/mongo/db/pipeline/document_source_bson_array.cpp
@@ -49,22 +49,18 @@ namespace mongo {
}
DocumentSourceBsonArray::DocumentSourceBsonArray(
- BSONElement *pBsonElement,
+ const BSONObj& array,
const intrusive_ptr<ExpressionContext> &pExpCtx)
: DocumentSource(pExpCtx)
- , embeddedObject(pBsonElement->embeddedObject())
+ , embeddedObject(array)
, arrayIterator(embeddedObject)
{}
intrusive_ptr<DocumentSourceBsonArray> DocumentSourceBsonArray::create(
- BSONElement *pBsonElement,
- const intrusive_ptr<ExpressionContext> &pExpCtx) {
+ const BSONObj& array,
+ const intrusive_ptr<ExpressionContext> &pExpCtx) {
- verify(pBsonElement->type() == Array);
- intrusive_ptr<DocumentSourceBsonArray> pSource(
- new DocumentSourceBsonArray(pBsonElement, pExpCtx));
-
- return pSource;
+ return new DocumentSourceBsonArray(array, pExpCtx);
}
Value DocumentSourceBsonArray::serialize(bool explain) const {
diff --git a/src/mongo/db/pipeline/document_source_command_shards.cpp b/src/mongo/db/pipeline/document_source_command_shards.cpp
index df4a99e8a7e..8c4af2b97f0 100644
--- a/src/mongo/db/pipeline/document_source_command_shards.cpp
+++ b/src/mongo/db/pipeline/document_source_command_shards.cpp
@@ -97,7 +97,7 @@ namespace mongo {
continue;
}
- pBsonSource = DocumentSourceBsonArray::create(&resultArray, pExpCtx);
+ pBsonSource = DocumentSourceBsonArray::create(resultArray.Obj(), pExpCtx);
}
if (boost::optional<Document> out = pBsonSource->getNext())
diff --git a/src/mongo/db/pipeline/document_source_geo_near.cpp b/src/mongo/db/pipeline/document_source_geo_near.cpp
index ae3b1f03d0f..ac5e43f5733 100644
--- a/src/mongo/db/pipeline/document_source_geo_near.cpp
+++ b/src/mongo/db/pipeline/document_source_geo_near.cpp
@@ -160,10 +160,10 @@ namespace mongo {
}
intrusive_ptr<DocumentSource> DocumentSourceGeoNear::createFromBson(
- BSONElement *pBsonElement,
+ BSONElement elem,
const intrusive_ptr<ExpressionContext> &pCtx) {
intrusive_ptr<DocumentSourceGeoNear> out = new DocumentSourceGeoNear(pCtx);
- out->parseOptions(pBsonElement->embeddedObjectUserCheck());
+ out->parseOptions(elem.embeddedObjectUserCheck());
return out;
}
diff --git a/src/mongo/db/pipeline/document_source_group.cpp b/src/mongo/db/pipeline/document_source_group.cpp
index 6acf53e4fec..aacae8fe669 100644
--- a/src/mongo/db/pipeline/document_source_group.cpp
+++ b/src/mongo/db/pipeline/document_source_group.cpp
@@ -211,16 +211,16 @@ namespace mongo {
static const size_t NGroupOp = sizeof(GroupOpTable)/sizeof(GroupOpTable[0]);
intrusive_ptr<DocumentSource> DocumentSourceGroup::createFromBson(
- BSONElement *pBsonElement,
- const intrusive_ptr<ExpressionContext> &pExpCtx) {
+ BSONElement elem,
+ const intrusive_ptr<ExpressionContext> &pExpCtx) {
uassert(15947, "a group's fields must be specified in an object",
- pBsonElement->type() == Object);
+ elem.type() == Object);
intrusive_ptr<DocumentSourceGroup> pGroup(
DocumentSourceGroup::create(pExpCtx));
bool idSet = false;
- BSONObj groupObj(pBsonElement->Obj());
+ BSONObj groupObj(elem.Obj());
BSONObjIterator groupIterator(groupObj);
while(groupIterator.more()) {
BSONElement groupField(groupIterator.next());
@@ -238,10 +238,7 @@ namespace mongo {
group-by key.
*/
Expression::ObjectCtx oCtx(Expression::ObjectCtx::DOCUMENT_OK);
- intrusive_ptr<Expression> pId(
- Expression::parseObject(&groupField, &oCtx));
-
- pGroup->setIdExpression(pId);
+ pGroup->setIdExpression(Expression::parseObject(groupField.Obj(), &oCtx));
idSet = true;
}
else if (groupType == String) {
@@ -305,10 +302,8 @@ namespace mongo {
BSONType elementType = subElement.type();
if (elementType == Object) {
- Expression::ObjectCtx oCtx(
- Expression::ObjectCtx::DOCUMENT_OK);
- pGroupExpr = Expression::parseObject(
- &subElement, &oCtx);
+ Expression::ObjectCtx oCtx(Expression::ObjectCtx::DOCUMENT_OK);
+ pGroupExpr = Expression::parseObject(subElement.Obj(), &oCtx);
}
else if (elementType == Array) {
uasserted(15953, str::stream()
diff --git a/src/mongo/db/pipeline/document_source_limit.cpp b/src/mongo/db/pipeline/document_source_limit.cpp
index e4cb0085ad8..56ea8a598f3 100644
--- a/src/mongo/db/pipeline/document_source_limit.cpp
+++ b/src/mongo/db/pipeline/document_source_limit.cpp
@@ -88,12 +88,12 @@ namespace mongo {
}
intrusive_ptr<DocumentSource> DocumentSourceLimit::createFromBson(
- BSONElement *pBsonElement,
- const intrusive_ptr<ExpressionContext> &pExpCtx) {
+ BSONElement elem,
+ const intrusive_ptr<ExpressionContext> &pExpCtx) {
uassert(15957, "the limit must be specified as a number",
- pBsonElement->isNumber());
+ elem.isNumber());
- long long limit = pBsonElement->numberLong();
+ long long limit = elem.numberLong();
return DocumentSourceLimit::create(pExpCtx, limit);
}
}
diff --git a/src/mongo/db/pipeline/document_source_match.cpp b/src/mongo/db/pipeline/document_source_match.cpp
index 75394357fa6..98df5604645 100644
--- a/src/mongo/db/pipeline/document_source_match.cpp
+++ b/src/mongo/db/pipeline/document_source_match.cpp
@@ -79,17 +79,14 @@ namespace mongo {
}
intrusive_ptr<DocumentSource> DocumentSourceMatch::createFromBson(
- BSONElement *pBsonElement,
- const intrusive_ptr<ExpressionContext> &pExpCtx) {
+ BSONElement elem,
+ const intrusive_ptr<ExpressionContext> &pExpCtx) {
uassert(15959, "the match filter must be an expression in an object",
- pBsonElement->type() == Object);
+ elem.type() == Object);
- uassertNoDisallowedClauses(pBsonElement->Obj());
+ uassertNoDisallowedClauses(elem.Obj());
- intrusive_ptr<DocumentSourceMatch> pMatcher(
- new DocumentSourceMatch(pBsonElement->Obj(), pExpCtx));
-
- return pMatcher;
+ return new DocumentSourceMatch(elem.Obj(), pExpCtx);
}
void DocumentSourceMatch::toMatcherBson(BSONObjBuilder *pBuilder) const {
diff --git a/src/mongo/db/pipeline/document_source_merge_cursors.cpp b/src/mongo/db/pipeline/document_source_merge_cursors.cpp
index d3f4c5f1bcf..d89d1475c09 100644
--- a/src/mongo/db/pipeline/document_source_merge_cursors.cpp
+++ b/src/mongo/db/pipeline/document_source_merge_cursors.cpp
@@ -59,14 +59,14 @@ namespace mongo {
}
intrusive_ptr<DocumentSource> DocumentSourceMergeCursors::createFromBson(
- BSONElement* pBsonElement,
+ BSONElement elem,
const intrusive_ptr<ExpressionContext>& pExpCtx) {
- massert(17026, string("Expected an Array, but got a ") + typeName(pBsonElement->type()),
- pBsonElement->type() == Array);
+ massert(17026, string("Expected an Array, but got a ") + typeName(elem.type()),
+ elem.type() == Array);
CursorIds cursorIds;
- BSONObj array = pBsonElement->embeddedObject();
+ BSONObj array = elem.embeddedObject();
BSONForEach(cursor, array) {
massert(17027, string("Expected an Object, but got a ") + typeName(cursor.type()),
cursor.type() == Object);
diff --git a/src/mongo/db/pipeline/document_source_out.cpp b/src/mongo/db/pipeline/document_source_out.cpp
index de0944f6ab1..b29dfbf2175 100644
--- a/src/mongo/db/pipeline/document_source_out.cpp
+++ b/src/mongo/db/pipeline/document_source_out.cpp
@@ -164,13 +164,13 @@ namespace mongo {
{}
intrusive_ptr<DocumentSource> DocumentSourceOut::createFromBson(
- BSONElement *pBsonElement,
+ BSONElement elem,
const intrusive_ptr<ExpressionContext> &pExpCtx) {
uassert(16990, str::stream() << "$out only supports a string argument, not "
- << typeName(pBsonElement->type()),
- pBsonElement->type() == String);
+ << typeName(elem.type()),
+ elem.type() == String);
- NamespaceString outputNs(pExpCtx->ns.db().toString() + '.' + pBsonElement->str());
+ NamespaceString outputNs(pExpCtx->ns.db().toString() + '.' + elem.str());
return new DocumentSourceOut(outputNs, pExpCtx);
}
diff --git a/src/mongo/db/pipeline/document_source_project.cpp b/src/mongo/db/pipeline/document_source_project.cpp
index 916ea45d34e..1c274c1989a 100644
--- a/src/mongo/db/pipeline/document_source_project.cpp
+++ b/src/mongo/db/pipeline/document_source_project.cpp
@@ -99,13 +99,13 @@ namespace mongo {
}
intrusive_ptr<DocumentSource> DocumentSourceProject::createFromBson(
- BSONElement *pBsonElement,
+ BSONElement elem,
const intrusive_ptr<ExpressionContext> &pExpCtx) {
/* validate */
uassert(15969, str::stream() << projectName <<
" specification must be an object",
- pBsonElement->type() == Object);
+ elem.type() == Object);
Expression::ObjectCtx objectCtx(
Expression::ObjectCtx::DOCUMENT_OK
@@ -113,14 +113,14 @@ namespace mongo {
| Expression::ObjectCtx::INCLUSION_OK
);
- intrusive_ptr<Expression> parsed = Expression::parseObject(pBsonElement, &objectCtx);
+ intrusive_ptr<Expression> parsed = Expression::parseObject(elem.Obj(), &objectCtx);
ExpressionObject* exprObj = dynamic_cast<ExpressionObject*>(parsed.get());
massert(16402, "parseObject() returned wrong type of Expression", exprObj);
uassert(16403, "$projection requires at least one output field", exprObj->getFieldCount());
intrusive_ptr<DocumentSourceProject> pProject(new DocumentSourceProject(pExpCtx, exprObj));
- BSONObj projectObj = pBsonElement->Obj();
+ BSONObj projectObj = elem.Obj();
pProject->_raw = projectObj.getOwned(); // probably not necessary, but better to be safe
#if defined(_DEBUG)
diff --git a/src/mongo/db/pipeline/document_source_redact.cpp b/src/mongo/db/pipeline/document_source_redact.cpp
index 91c5b91079e..e46758dae91 100644
--- a/src/mongo/db/pipeline/document_source_redact.cpp
+++ b/src/mongo/db/pipeline/document_source_redact.cpp
@@ -144,14 +144,14 @@ namespace mongo {
}
intrusive_ptr<DocumentSource> DocumentSourceRedact::createFromBson(
- BSONElement* bsonElement,
+ BSONElement elem,
const intrusive_ptr<ExpressionContext>& expCtx) {
uassert(17054, str::stream() << redactName << " specification must be an object",
- bsonElement->type() == Object);
+ elem.type() == Object);
Expression::ObjectCtx oCtx(0);
- intrusive_ptr<Expression> expression = Expression::parseObject(bsonElement, &oCtx);
+ intrusive_ptr<Expression> expression = Expression::parseObject(elem.Obj(), &oCtx);
return new DocumentSourceRedact(expCtx, expression);
}
diff --git a/src/mongo/db/pipeline/document_source_skip.cpp b/src/mongo/db/pipeline/document_source_skip.cpp
index 9ffdc1762cf..28d83ffd471 100644
--- a/src/mongo/db/pipeline/document_source_skip.cpp
+++ b/src/mongo/db/pipeline/document_source_skip.cpp
@@ -89,16 +89,16 @@ namespace mongo {
}
intrusive_ptr<DocumentSource> DocumentSourceSkip::createFromBson(
- BSONElement *pBsonElement,
- const intrusive_ptr<ExpressionContext> &pExpCtx) {
+ BSONElement elem,
+ const intrusive_ptr<ExpressionContext> &pExpCtx) {
uassert(15972, str::stream() << DocumentSourceSkip::skipName <<
": the value to skip must be a number",
- pBsonElement->isNumber());
+ elem.isNumber());
intrusive_ptr<DocumentSourceSkip> pSkip(
DocumentSourceSkip::create(pExpCtx));
- pSkip->_skip = pBsonElement->numberLong();
+ pSkip->_skip = elem.numberLong();
uassert(15956, str::stream() << DocumentSourceSkip::skipName <<
": the number to skip cannot be negative",
pSkip->_skip >= 0);
diff --git a/src/mongo/db/pipeline/document_source_sort.cpp b/src/mongo/db/pipeline/document_source_sort.cpp
index 0d2378a933b..40142a2f034 100644
--- a/src/mongo/db/pipeline/document_source_sort.cpp
+++ b/src/mongo/db/pipeline/document_source_sort.cpp
@@ -126,13 +126,13 @@ namespace mongo {
intrusive_ptr<DocumentSource> DocumentSourceSort::createFromBson(
- BSONElement *pBsonElement,
- const intrusive_ptr<ExpressionContext> &pExpCtx) {
+ BSONElement elem,
+ const intrusive_ptr<ExpressionContext> &pExpCtx) {
uassert(15973, str::stream() << " the " <<
sortName << " key specification must be an object",
- pBsonElement->type() == Object);
+ elem.type() == Object);
- return create(pExpCtx, pBsonElement->embeddedObject());
+ return create(pExpCtx, elem.embeddedObject());
}
diff --git a/src/mongo/db/pipeline/document_source_unwind.cpp b/src/mongo/db/pipeline/document_source_unwind.cpp
index 5834feffa87..890214c4118 100644
--- a/src/mongo/db/pipeline/document_source_unwind.cpp
+++ b/src/mongo/db/pipeline/document_source_unwind.cpp
@@ -158,16 +158,16 @@ namespace mongo {
}
intrusive_ptr<DocumentSource> DocumentSourceUnwind::createFromBson(
- BSONElement *pBsonElement,
- const intrusive_ptr<ExpressionContext> &pExpCtx) {
+ BSONElement elem,
+ const intrusive_ptr<ExpressionContext> &pExpCtx) {
/*
The value of $unwind should just be a field path.
*/
uassert(15981, str::stream() << "the " << unwindName <<
" field path must be specified as a string",
- pBsonElement->type() == String);
+ elem.type() == String);
- string prefixedPathString(pBsonElement->str());
+ string prefixedPathString(elem.str());
string pathString(Expression::removeFieldPrefix(prefixedPathString));
intrusive_ptr<DocumentSourceUnwind> pUnwind(new DocumentSourceUnwind(pExpCtx));
pUnwind->unwindPath(FieldPath(pathString));
diff --git a/src/mongo/db/pipeline/expression.cpp b/src/mongo/db/pipeline/expression.cpp
index 8c6fbfc053d..8fb62a388a8 100644
--- a/src/mongo/db/pipeline/expression.cpp
+++ b/src/mongo/db/pipeline/expression.cpp
@@ -138,8 +138,7 @@ namespace mongo {
return string(pPrefixedField + 1);
}
- intrusive_ptr<Expression> Expression::parseObject(
- BSONElement *pBsonElement, ObjectCtx *pCtx) {
+ intrusive_ptr<Expression> Expression::parseObject(BSONObj obj, ObjectCtx *pCtx) {
/*
An object expression can take any of the following forms:
@@ -151,7 +150,6 @@ namespace mongo {
intrusive_ptr<ExpressionObject> pExpressionObject; // alt result
enum { UNKNOWN, NOTOPERATOR, OPERATOR } kind = UNKNOWN;
- BSONObj obj(pBsonElement->Obj());
if (obj.isEmpty())
return ExpressionObject::create();
BSONObjIterator iter(obj);
@@ -203,9 +201,9 @@ namespace mongo {
ObjectCtx oCtx(
(pCtx->documentOk() ? ObjectCtx::DOCUMENT_OK : 0)
| (pCtx->inclusionOk() ? ObjectCtx::INCLUSION_OK : 0));
- intrusive_ptr<Expression> pNested(
- parseObject(&fieldElement, &oCtx));
- pExpressionObject->addField(fieldName, pNested);
+
+ pExpressionObject->addField(fieldName,
+ parseObject(fieldElement.Obj(), &oCtx));
break;
}
case String: {
@@ -301,7 +299,7 @@ namespace {
}
else if (type == Object) {
ObjectCtx oCtx(ObjectCtx::DOCUMENT_OK);
- return Expression::parseObject(&exprElement, &oCtx);
+ return Expression::parseObject(exprElement.Obj(), &oCtx);
}
else {
return ExpressionConstant::parse(exprElement);
diff --git a/src/mongo/db/pipeline/expression.h b/src/mongo/db/pipeline/expression.h
index 8aa558bfc3b..3ad7b3dbafa 100644
--- a/src/mongo/db/pipeline/expression.h
+++ b/src/mongo/db/pipeline/expression.h
@@ -142,15 +142,14 @@ namespace mongo {
};
/*
- Parse a BSONElement Object. The object could represent a functional
+ Parse BSON Object. The object could represent a functional
expression or a Document expression.
- @param pBsonElement the element representing the object
+ @param obj the object to parse
@param pCtx a MiniCtx representing the options above
@returns the parsed Expression
*/
- static intrusive_ptr<Expression> parseObject(
- BSONElement *pBsonElement, ObjectCtx *pCtx);
+ static intrusive_ptr<Expression> parseObject(BSONObj obj, ObjectCtx *pCtx);
/*
Parse a BSONElement Object which has already been determined to be
diff --git a/src/mongo/db/pipeline/pipeline.cpp b/src/mongo/db/pipeline/pipeline.cpp
index a93cde45d83..eaad09c51f0 100644
--- a/src/mongo/db/pipeline/pipeline.cpp
+++ b/src/mongo/db/pipeline/pipeline.cpp
@@ -60,7 +60,7 @@ namespace mongo {
struct StageDesc {
const char *pName;
intrusive_ptr<DocumentSource> (*pFactory)(
- BSONElement *, const intrusive_ptr<ExpressionContext> &);
+ BSONElement, const intrusive_ptr<ExpressionContext> &);
};
/* this table must be in alphabetical order by name for bsearch() */
@@ -189,7 +189,7 @@ namespace mongo {
uassert(16436,
str::stream() << "Unrecognized pipeline stage name: '" << stageName << "'",
pDesc);
- intrusive_ptr<DocumentSource> stage = (*pDesc->pFactory)(&stageSpec, pCtx);
+ intrusive_ptr<DocumentSource> stage = pDesc->pFactory(stageSpec, pCtx);
verify(stage);
stage->setPipelineStep(iStep);
sources.push_back(stage);
diff --git a/src/mongo/dbtests/documentsourcetests.cpp b/src/mongo/dbtests/documentsourcetests.cpp
index 076b8bafe3f..9440396c0b8 100644
--- a/src/mongo/dbtests/documentsourcetests.cpp
+++ b/src/mongo/dbtests/documentsourcetests.cpp
@@ -328,7 +328,7 @@ namespace DocumentSourceTests {
void createLimit( int limit ) {
BSONObj spec = BSON( "$limit" << limit );
BSONElement specElement = spec.firstElement();
- _limit = DocumentSourceLimit::createFromBson( &specElement, ctx() );
+ _limit = DocumentSourceLimit::createFromBson( specElement, ctx() );
}
DocumentSource* limit() { return _limit.get(); }
private:
@@ -369,7 +369,7 @@ namespace DocumentSourceTests {
BSONObj spec = BSON( "$match" << BSON( "a" << 1 ) );
BSONElement specElement = spec.firstElement();
intrusive_ptr<DocumentSource> match =
- DocumentSourceMatch::createFromBson( &specElement, ctx() );
+ DocumentSourceMatch::createFromBson( specElement, ctx() );
match->setSource( source() );
createLimit( 1 );
@@ -414,7 +414,7 @@ namespace DocumentSourceTests {
expressionContext->inShard = inShard;
expressionContext->tempDir = storageGlobalParams.dbpath + "/_tmp";
- _group = DocumentSourceGroup::createFromBson( &specElement, expressionContext );
+ _group = DocumentSourceGroup::createFromBson( specElement, expressionContext );
assertRoundTrips( _group );
_group->setSource( source() );
}
@@ -434,7 +434,7 @@ namespace DocumentSourceTests {
BSONObj spec = toBson(group);
BSONElement specElement = spec.firstElement();
intrusive_ptr<DocumentSource> generated =
- DocumentSourceGroup::createFromBson( &specElement, ctx() );
+ DocumentSourceGroup::createFromBson( specElement, ctx() );
ASSERT_EQUALS( spec, toBson( generated ) );
}
intrusive_ptr<DocumentSource> _group;
@@ -486,7 +486,7 @@ namespace DocumentSourceTests {
void run() {
BSONObj spec = BSON( "$group" << "foo" );
BSONElement specElement = spec.firstElement();
- ASSERT_THROWS( DocumentSourceGroup::createFromBson( &specElement, ctx() ),
+ ASSERT_THROWS( DocumentSourceGroup::createFromBson( specElement, ctx() ),
UserException );
}
};
@@ -817,7 +817,7 @@ namespace DocumentSourceTests {
BSONElement sourceDataElement = sourceData.firstElement();
// Create a source with synthetic data.
intrusive_ptr<DocumentSourceBsonArray> source =
- DocumentSourceBsonArray::create( &sourceDataElement, ctx() );
+ DocumentSourceBsonArray::create( sourceDataElement.Obj(), ctx() );
// Create a group source.
createGroup( BSON( "_id" << "$x" << "list" << BSON( "$push" << "$y" ) ) );
// Create a merger version of the source.
@@ -892,7 +892,7 @@ namespace DocumentSourceTests {
void createProject( const BSONObj& projection = BSON( "a" << true ) ) {
BSONObj spec = BSON( "$project" << projection );
BSONElement specElement = spec.firstElement();
- _project = DocumentSourceProject::createFromBson( &specElement, ctx() );
+ _project = DocumentSourceProject::createFromBson( specElement, ctx() );
checkBsonRepresentation( spec );
_project->setSource( source() );
}
@@ -954,7 +954,7 @@ namespace DocumentSourceTests {
void run() {
BSONObj spec = BSON( "$project" << "foo" );
BSONElement specElement = spec.firstElement();
- ASSERT_THROWS( DocumentSourceProject::createFromBson( &specElement, ctx() ),
+ ASSERT_THROWS( DocumentSourceProject::createFromBson( specElement, ctx() ),
UserException );
}
};
@@ -1038,7 +1038,7 @@ namespace DocumentSourceTests {
void createSort( const BSONObj& sortKey = BSON( "a" << 1 ) ) {
BSONObj spec = BSON( "$sort" << sortKey );
BSONElement specElement = spec.firstElement();
- _sort = DocumentSourceSort::createFromBson( &specElement, ctx() );
+ _sort = DocumentSourceSort::createFromBson( specElement, ctx() );
checkBsonRepresentation( spec );
_sort->setSource( source() );
}
@@ -1097,7 +1097,7 @@ namespace DocumentSourceTests {
intrusive_ptr<DocumentSource> mkLimit(int limit) {
BSONObj obj = BSON("$limit" << limit);
BSONElement e = obj.firstElement();
- return mongo::DocumentSourceLimit::createFromBson(&e, ctx());
+ return mongo::DocumentSourceLimit::createFromBson(e, ctx());
}
};
@@ -1199,7 +1199,7 @@ namespace DocumentSourceTests {
void run() {
BSONObj spec = BSON( "$sort" << 1 );
BSONElement specElement = spec.firstElement();
- ASSERT_THROWS( DocumentSourceSort::createFromBson( &specElement, ctx() ),
+ ASSERT_THROWS( DocumentSourceSort::createFromBson( specElement, ctx() ),
UserException );
}
};
@@ -1370,7 +1370,7 @@ namespace DocumentSourceTests {
void createUnwind( const string& unwindFieldPath = "$a" ) {
BSONObj spec = BSON( "$unwind" << unwindFieldPath );
BSONElement specElement = spec.firstElement();
- _unwind = DocumentSourceUnwind::createFromBson( &specElement, ctx() );
+ _unwind = DocumentSourceUnwind::createFromBson( specElement, ctx() );
checkBsonRepresentation( spec );
_unwind->setSource( source() );
}
diff --git a/src/mongo/dbtests/expressiontests.cpp b/src/mongo/dbtests/expressiontests.cpp
index fa885d05ec0..3d8e35cf694 100644
--- a/src/mongo/dbtests/expressiontests.cpp
+++ b/src/mongo/dbtests/expressiontests.cpp
@@ -1245,7 +1245,7 @@ namespace ExpressionTests {
BSONObj spec = BSON( "" << BSON( "a" << "$x" << "q" << "$r" ) );
BSONElement specElement = spec.firstElement();
Expression::ObjectCtx ctx( Expression::ObjectCtx::DOCUMENT_OK );
- testable->addOperand( Expression::parseObject( &specElement, &ctx ) );
+ testable->addOperand( Expression::parseObject( specElement.Obj(), &ctx ) );
assertDependencies( BSON_ARRAY( "ab.c" << "r" << "x" ), testable );
}
private:
@@ -2361,7 +2361,7 @@ namespace ExpressionTests {
BSONElement specElement = specObject.firstElement();
Expression::ObjectCtx context = objectCtx();
intrusive_ptr<Expression> expression =
- Expression::parseObject( &specElement, &context );
+ Expression::parseObject( specElement.Obj(), &context );
ASSERT_EQUALS( expectedBson(), expressionToBson( expression ) );
}
protected:
@@ -2379,7 +2379,7 @@ namespace ExpressionTests {
BSONObj specObject = BSON( "" << spec() );
BSONElement specElement = specObject.firstElement();
Expression::ObjectCtx context = objectCtx();
- ASSERT_THROWS( Expression::parseObject( &specElement, &context ),
+ ASSERT_THROWS( Expression::parseObject( specElement.Obj(), &context ),
UserException );
}
protected:
@@ -2397,7 +2397,7 @@ namespace ExpressionTests {
BSONElement specElement = specObject.firstElement();
Expression::ObjectCtx context =
Expression::ObjectCtx( Expression::ObjectCtx::DOCUMENT_OK );
- ASSERT_THROWS( Expression::parseObject( &specElement, &context ),
+ ASSERT_THROWS( Expression::parseObject( specElement.Obj(), &context ),
UserException );
}
};