|  | @@ -33,6 +33,7 @@ var GroupDocumentSource = module.exports = function GroupDocumentSource(expCtx)
 | 
	
		
			
				|  |  |  	this.currentAccumulators = [];
 | 
	
		
			
				|  |  |  	this.groups = {}; // GroupsType Value -> Accumulators[]
 | 
	
		
			
				|  |  |  	this.groupsKeys = []; // This is to faciliate easier look up of groups
 | 
	
		
			
				|  |  | +	this.originalGroupsKeys = [];
 | 
	
		
			
				|  |  |  	this.variables = null;
 | 
	
		
			
				|  |  |  	this.fieldNames = [];
 | 
	
		
			
				|  |  |  	this.idFieldNames = [];
 | 
	
	
		
			
				|  | @@ -107,9 +108,10 @@ proto.getNext = function getNext(callback) {
 | 
	
		
			
				|  |  |  					return next(null, null);
 | 
	
		
			
				|  |  |  				}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -				var id = self.groupsKeys[self.currentGroupsKeysIndex],
 | 
	
		
			
				|  |  | -					accumulators = self.groups[id],
 | 
	
		
			
				|  |  | -					out = self.makeDocument(JSON.parse(id), accumulators, self.expCtx.inShard);
 | 
	
		
			
				|  |  | +				var id = self.originalGroupsKeys[self.currentGroupsKeysIndex],
 | 
	
		
			
				|  |  | +					stringifiedId = self.groupsKeys[self.currentGroupsKeysIndex],
 | 
	
		
			
				|  |  | +					accumulators = self.groups[stringifiedId],
 | 
	
		
			
				|  |  | +					out = self.makeDocument(id, accumulators, self.expCtx.inShard);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  				if(++self.currentGroupsKeysIndex === self.groupsKeys.length) {
 | 
	
		
			
				|  |  |  					self.dispose();
 | 
	
	
		
			
				|  | @@ -310,6 +312,7 @@ proto.populate = function populate(callback) {
 | 
	
		
			
				|  |  |  					group = self.groups[groupKey];
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  				if(!group) {
 | 
	
		
			
				|  |  | +					self.originalGroupsKeys.push(id);
 | 
	
		
			
				|  |  |  					self.groupsKeys.push(groupKey);
 | 
	
		
			
				|  |  |  					group = [];
 | 
	
		
			
				|  |  |  					self.groups[groupKey] = group;
 |