summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 4ce1d4031db..31a72df4772 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 {