summaryrefslogtreecommitdiff
path: root/src/mongo/bson/bsonobj.cpp
diff options
context:
space:
mode:
authorGeert Bosch <geert@mongodb.com>2017-06-15 00:20:33 -0400
committerGeert Bosch <geert@mongodb.com>2017-06-23 15:11:09 -0400
commita69ae445303fc4821c6745866b3902623a385c1c (patch)
tree177cab03d8078defe675fd0dff15349cc32401c0 /src/mongo/bson/bsonobj.cpp
parent3bb0f6030b5609002049ea2156e97fe4c6c05d5d (diff)
downloadmongo-a69ae445303fc4821c6745866b3902623a385c1c.tar.gz
SERVER-27992 Use UUIDs for replication
Diffstat (limited to 'src/mongo/bson/bsonobj.cpp')
-rw-r--r--src/mongo/bson/bsonobj.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/mongo/bson/bsonobj.cpp b/src/mongo/bson/bsonobj.cpp
index 2f7133a2a63..06f446c9c05 100644
--- a/src/mongo/bson/bsonobj.cpp
+++ b/src/mongo/bson/bsonobj.cpp
@@ -503,6 +503,26 @@ bool BSONObj::getObjectID(BSONElement& e) const {
return false;
}
+BSONObj BSONObj::addField(const BSONElement& field) const {
+ if (!field.ok())
+ return copy();
+ BSONObjBuilder b;
+ StringData name = field.fieldNameStringData();
+ bool added = false;
+ for (auto e : *this) {
+ if (e.fieldNameStringData() == name) {
+ if (!added)
+ b.append(field);
+ added = true;
+ } else {
+ b.append(e);
+ }
+ }
+ if (!added)
+ b.append(field);
+ return b.obj();
+}
+
BSONObj BSONObj::removeField(StringData name) const {
BSONObjBuilder b;
BSONObjIterator i(*this);