summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Reams <jbreams@mongodb.com>2016-03-23 11:36:21 -0400
committerJonathan Reams <jbreams@mongodb.com>2016-03-28 16:38:34 -0400
commit6adda9f7dde0bf62b9ff8d27ade8f1bb6e574fec (patch)
tree12ec96f67b077b542ca4dbfec685c0884d3735e0
parent44fbaf79a3d76ce3476618759385a585b8f3fa45 (diff)
downloadmongo-6adda9f7dde0bf62b9ff8d27ade8f1bb6e574fec.tar.gz
SERVER-23191 group should pass an owned BSONObj to the reduce function
-rw-r--r--jstests/core/group9.js20
-rw-r--r--src/mongo/db/exec/group.cpp3
2 files changed, 22 insertions, 1 deletions
diff --git a/jstests/core/group9.js b/jstests/core/group9.js
new file mode 100644
index 00000000000..a7d9a0d128e
--- /dev/null
+++ b/jstests/core/group9.js
@@ -0,0 +1,20 @@
+(function() {
+ 'use strict';
+ var t = db.group_owned;
+ t.drop();
+
+ assert.writeOK(t.insert({_id: 1, subdoc: {id: 1}}));
+ assert.writeOK(t.insert({_id: 2, subdoc: {id: 2}}));
+
+ var result = t.group({
+ key: {'subdoc.id': 1},
+ reduce: function(doc, value) {
+ value.subdoc = doc.subdoc;
+ return value;
+ },
+ initial: {},
+ finalize: function(res) {}
+ });
+
+ assert(result.length == 2);
+}());
diff --git a/src/mongo/db/exec/group.cpp b/src/mongo/db/exec/group.cpp
index c03e7643f13..19729bbacf9 100644
--- a/src/mongo/db/exec/group.cpp
+++ b/src/mongo/db/exec/group.cpp
@@ -148,7 +148,8 @@ Status GroupStage::processObject(const BSONObj& obj) {
}
}
- _scope->setObject("obj", obj, true);
+ BSONObj objCopy = obj.getOwned();
+ _scope->setObject("obj", objCopy, true);
_scope->setNumber("n", n - 1);
try {