Przeglądaj źródła

refs #2892: Fixed but where _id is stringified

Jared Hall 12 lat temu
rodzic
commit
82622f794e

+ 1 - 0
README.md

@@ -94,6 +94,7 @@ Here is a list of the major items where we have deviated from the MongoDB code a
         * DESIGN: To further this, the `CompareExpression` class doesn't provide any of it's various `create{FOO}` helpers so compensate I am just binding the appropriate args to the `constructor` to create a similar factory
         * DESIGN: To further this, the `CompareExpression` class doesn't provide any of it's various `create{FOO}` helpers so compensate I am just binding the appropriate args to the `constructor` to create a similar factory
     * `DocumentSource` classes
     * `DocumentSource` classes
       * DESIGN: We have implemented a `reset` method for all document sources so that we can reuse them against different streams of data
       * DESIGN: We have implemented a `reset` method for all document sources so that we can reuse them against different streams of data
+	  * DESIGN: GroupDocumentSource stores copies of all unique _id's that it accumulates to dodge a javascript Stringify/Parse issue with dates
 
 
 
 
 TODO
 TODO

+ 4 - 1
lib/pipeline/documentSources/GroupDocumentSource.js

@@ -23,6 +23,7 @@ var GroupDocumentSource = module.exports = function GroupDocumentSource(expCtx)
 	this.idExpression = null;
 	this.idExpression = null;
 	this.groups = {}; // GroupsType Value -> Accumulators[]
 	this.groups = {}; // GroupsType Value -> Accumulators[]
 	this.groupsKeys = []; // This is to faciliate easier look up of groups
 	this.groupsKeys = []; // This is to faciliate easier look up of groups
+	this.originalGroupsKeys = []; // This stores the original group key un-hashed/stringified/whatever
 
 
 	this.fieldNames = [];
 	this.fieldNames = [];
 	this.accumulatorFactories = [];
 	this.accumulatorFactories = [];
@@ -225,6 +226,7 @@ proto.populate = function populate() {
 		} else {
 		} else {
 			this.groups[idHash] = group = [];
 			this.groups[idHash] = group = [];
 			this.groupsKeys[this.currentGroupsKeysIndex] = idHash;
 			this.groupsKeys[this.currentGroupsKeysIndex] = idHash;
+			this.originalGroupsKeys[this.currentGroupsKeysIndex] = (_id && typeof _id === 'object') ? Document.clone(_id) : _id;
 			++this.currentGroupsKeysIndex;
 			++this.currentGroupsKeysIndex;
 			for (var ai = 0; ai < this.accumulatorFactories.length; ++ai) {
 			for (var ai = 0; ai < this.accumulatorFactories.length; ++ai) {
 				var accumulator = new this.accumulatorFactories[ai]();
 				var accumulator = new this.accumulatorFactories[ai]();
@@ -251,10 +253,11 @@ proto.populate = function populate() {
 
 
 proto.makeDocument = function makeDocument(groupKeyIndex) {
 proto.makeDocument = function makeDocument(groupKeyIndex) {
 	var groupKey = this.groupsKeys[groupKeyIndex],
 	var groupKey = this.groupsKeys[groupKeyIndex],
+		originalGroupKey = this.originalGroupsKeys[groupKeyIndex],
 		group = this.groups[groupKey],
 		group = this.groups[groupKey],
 		doc = {};
 		doc = {};
 
 
-	doc[Document.ID_PROPERTY_NAME] = JSON.parse(groupKey);
+	doc[Document.ID_PROPERTY_NAME] = originalGroupKey;
 
 
 	for (var i = 0; i < this.fieldNames.length; ++i) {
 	for (var i = 0; i < this.fieldNames.length; ++i) {
 		var fieldName = this.fieldNames[i],
 		var fieldName = this.fieldNames[i],