diff options
Diffstat (limited to 'src/mongo/bson')
-rw-r--r-- | src/mongo/bson/bsonobj.cpp | 20 | ||||
-rw-r--r-- | src/mongo/bson/bsonobj.h | 5 |
2 files changed, 18 insertions, 7 deletions
diff --git a/src/mongo/bson/bsonobj.cpp b/src/mongo/bson/bsonobj.cpp index 74d3edf1588..284058feecf 100644 --- a/src/mongo/bson/bsonobj.cpp +++ b/src/mongo/bson/bsonobj.cpp @@ -346,8 +346,7 @@ bool BSONObj::isFieldNamePrefixOf(const BSONObj& otherObj) const { return !a.more(); } -BSONObj BSONObj::extractFieldsUnDotted(const BSONObj& pattern) const { - BSONObjBuilder b; +void BSONObj::extractFieldsUndotted(BSONObjBuilder* b, const BSONObj& pattern) const { BSONObjIterator i(pattern); while (i.moreWithEOO()) { BSONElement e = i.next(); @@ -355,13 +354,17 @@ BSONObj BSONObj::extractFieldsUnDotted(const BSONObj& pattern) const { break; BSONElement x = getField(e.fieldName()); if (!x.eoo()) - b.appendAs(x, ""); + b->appendAs(x, ""); } - return b.obj(); } -BSONObj BSONObj::filterFieldsUndotted(const BSONObj& filter, bool inFilter) const { +BSONObj BSONObj::extractFieldsUndotted(const BSONObj& pattern) const { BSONObjBuilder b; + extractFieldsUndotted(&b, pattern); + return b.obj(); +} + +void BSONObj::filterFieldsUndotted(BSONObjBuilder* b, const BSONObj& filter, bool inFilter) const { BSONObjIterator i(*this); while (i.moreWithEOO()) { BSONElement e = i.next(); @@ -369,8 +372,13 @@ BSONObj BSONObj::filterFieldsUndotted(const BSONObj& filter, bool inFilter) cons break; BSONElement x = filter.getField(e.fieldName()); if ((x.eoo() && !inFilter) || (!x.eoo() && inFilter)) - b.append(e); + b->append(e); } +} + +BSONObj BSONObj::filterFieldsUndotted(const BSONObj& filter, bool inFilter) const { + BSONObjBuilder b; + filterFieldsUndotted(&b, filter, inFilter); return b.obj(); } diff --git a/src/mongo/bson/bsonobj.h b/src/mongo/bson/bsonobj.h index 215652bcd29..f22c9391bb6 100644 --- a/src/mongo/bson/bsonobj.h +++ b/src/mongo/bson/bsonobj.h @@ -52,6 +52,7 @@ namespace mongo { +class BSONObjBuilder; class BSONObjStlIterator; class ExtendedCanonicalV200Generator; class ExtendedRelaxedV200Generator; @@ -393,9 +394,11 @@ public: * this.extractFieldsUnDotted({b : "blah"}) -> {"" : 5} * */ - BSONObj extractFieldsUnDotted(const BSONObj& pattern) const; + BSONObj extractFieldsUndotted(const BSONObj& pattern) const; + void extractFieldsUndotted(BSONObjBuilder* b, const BSONObj& pattern) const; BSONObj filterFieldsUndotted(const BSONObj& filter, bool inFilter) const; + void filterFieldsUndotted(BSONObjBuilder* b, const BSONObj& filter, bool inFilter) const; BSONElement getFieldUsingIndexNames(StringData fieldName, const BSONObj& indexKey) const; |