summaryrefslogtreecommitdiff
path: root/bson
diff options
context:
space:
mode:
authorDwight <dwight@10gen.com>2011-07-05 11:39:36 -0400
committerDwight <dwight@10gen.com>2011-07-05 11:39:36 -0400
commite9170171f9f55e18a2bdf13d8d0b1dbfb2e71b8f (patch)
treec63e92eb5577a1e6780fb482e3f4e4de6ce385f7 /bson
parent611a71264a008ff8c53a3c37ea4e092a72b78258 (diff)
downloadmongo-e9170171f9f55e18a2bdf13d8d0b1dbfb2e71b8f.tar.gz
use new index version on reindex command
Diffstat (limited to 'bson')
-rw-r--r--bson/bson-inl.h11
-rw-r--r--bson/bsonobj.h5
2 files changed, 16 insertions, 0 deletions
diff --git a/bson/bson-inl.h b/bson/bson-inl.h
index 71b7c50bab7..54431549852 100644
--- a/bson/bson-inl.h
+++ b/bson/bson-inl.h
@@ -974,4 +974,15 @@ dodouble:
assert( ! j.more() );
}
+ inline BSONObj BSONObj::removeField(const StringData& name) const {
+ BSONObjBuilder b;
+ BSONObjIterator i(*this);
+ while ( i.more() ) {
+ BSONElement e = i.next();
+ const char *fname = e.fieldName();
+ if( strcmp(name.data(), fname) )
+ b.append(e);
+ }
+ return b.obj();
+ }
}
diff --git a/bson/bsonobj.h b/bson/bsonobj.h
index 1e0cb9f591b..cb1749142c1 100644
--- a/bson/bsonobj.h
+++ b/bson/bsonobj.h
@@ -148,6 +148,11 @@ namespace mongo {
/** note: addFields always adds _id even if not specified */
int addFields(BSONObj& from, set<string>& fields); /* returns n added */
+ /** remove specified field and return a new object with the remaining fields.
+ slowish as builds a full new object
+ */
+ BSONObj removeField(const StringData& name) const;
+
/** returns # of top level fields in the object
note: iterates to count the fields
*/