summaryrefslogtreecommitdiff
path: root/src/mongo/bson/bsonobjbuilder.h
diff options
context:
space:
mode:
authorSpencer Jackson <spencer.jackson@mongodb.com>2018-08-20 14:18:30 -0400
committerSpencer Jackson <spencer.jackson@mongodb.com>2018-09-17 17:21:40 -0400
commitf99914d14b76718f1fef879cfaabe23c0c8f0857 (patch)
treee1da0b70c4d958cd59e671166bec0dc9ce9f3a57 /src/mongo/bson/bsonobjbuilder.h
parentd246e38f3dad15b9919773ffe6a2fa59288034f2 (diff)
downloadmongo-f99914d14b76718f1fef879cfaabe23c0c8f0857.tar.gz
SERVER-36606: Allow construction of large BSON objects
Diffstat (limited to 'src/mongo/bson/bsonobjbuilder.h')
-rw-r--r--src/mongo/bson/bsonobjbuilder.h8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/mongo/bson/bsonobjbuilder.h b/src/mongo/bson/bsonobjbuilder.h
index ef92065d9a0..35402a3a3ed 100644
--- a/src/mongo/bson/bsonobjbuilder.h
+++ b/src/mongo/bson/bsonobjbuilder.h
@@ -666,9 +666,10 @@ public:
* The returned BSONObj will free the buffer when it is finished.
* @return owned BSONObj
*/
+ template <typename BSONTraits = BSONObj::DefaultSizeTrait>
BSONObj obj() {
massert(10335, "builder does not own memory", owned());
- auto out = done();
+ auto out = done<BSONTraits>();
out.shareOwnershipWith(_b.release());
return out;
}
@@ -678,8 +679,9 @@ public:
scope -- very important to keep in mind. Use obj() if you
would like the BSONObj to last longer than the builder.
*/
+ template <typename BSONTraits = BSONObj::DefaultSizeTrait>
BSONObj done() {
- return BSONObj(_done());
+ return BSONObj(_done(), BSONTraits{});
}
// Like 'done' above, but does not construct a BSONObj to return to the caller.
@@ -692,7 +694,7 @@ public:
Intended use case: append a field if not already there.
*/
BSONObj asTempObj() {
- BSONObj temp(_done());
+ BSONObj temp(_done(), BSONObj::LargeSizeTrait{});
_b.setlen(_b.len() - 1); // next append should overwrite the EOO
_b.reserveBytes(1); // Rereserve room for the real EOO
_doneCalled = false;