summaryrefslogtreecommitdiff
path: root/src/mongo/bson
diff options
context:
space:
mode:
authorGregory Noma <gregory.noma@gmail.com>2019-08-08 10:55:52 -0400
committerGregory Noma <gregory.noma@gmail.com>2019-08-08 10:55:52 -0400
commit75d6c5116dd1aefa6c6daebd2cab0d47498db706 (patch)
treec73225c0086d76612448cd947c9ccbc88c941150 /src/mongo/bson
parent8457da2f81b5378fa7485a151cb2255700a6c31a (diff)
downloadmongo-75d6c5116dd1aefa6c6daebd2cab0d47498db706.tar.gz
SERVER-41721 Make IndexAccessMethod::getKeys output a KeyString set
Diffstat (limited to 'src/mongo/bson')
-rw-r--r--src/mongo/bson/bsonobj.cpp19
-rw-r--r--src/mongo/bson/bsonobj.h4
2 files changed, 23 insertions, 0 deletions
diff --git a/src/mongo/bson/bsonobj.cpp b/src/mongo/bson/bsonobj.cpp
index 5985ec18976..0e44b7d398d 100644
--- a/src/mongo/bson/bsonobj.cpp
+++ b/src/mongo/bson/bsonobj.cpp
@@ -378,6 +378,25 @@ BSONObj BSONObj::replaceFieldNames(const BSONObj& names) const {
return b.obj();
}
+BSONObj BSONObj::stripFieldNames(const BSONObj& obj) {
+ if (!obj.hasFieldNames())
+ return obj;
+
+ BSONObjBuilder bb;
+ for (auto e : obj) {
+ bb.appendAs(e, StringData());
+ }
+ return bb.obj();
+}
+
+bool BSONObj::hasFieldNames() const {
+ for (auto e : *this) {
+ if (e.fieldName()[0])
+ return true;
+ }
+ return false;
+}
+
Status BSONObj::storageValidEmbedded() const {
BSONObjIterator i(*this);
diff --git a/src/mongo/bson/bsonobj.h b/src/mongo/bson/bsonobj.h
index 82efac98902..bf8559f7dbd 100644
--- a/src/mongo/bson/bsonobj.h
+++ b/src/mongo/bson/bsonobj.h
@@ -532,6 +532,10 @@ public:
passed object. */
BSONObj replaceFieldNames(const BSONObj& obj) const;
+ static BSONObj stripFieldNames(const BSONObj& obj);
+
+ bool hasFieldNames() const;
+
/**
* Returns true if this object is valid according to the specified BSON version, and returns
* false otherwise.