From 1a67730bc62ee939741a79e0b96117469a8666ca Mon Sep 17 00:00:00 2001 From: Mootaz Dinana Date: Thu, 27 Oct 2016 17:28:06 +0200 Subject: [PATCH] Fix group aggregate field name cannot contain dot mongo error If the field to be summed/averaged/counted/etc.. is a on a sub-document then the group aggregate field name will contain a dot and mongoDb does not allow this, chose to replace by dash. --- lib/query/aggregate.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/query/aggregate.js b/lib/query/aggregate.js index 4fd06911f..9964145d8 100644 --- a/lib/query/aggregate.js +++ b/lib/query/aggregate.js @@ -50,25 +50,25 @@ Aggregate.prototype.build = function build(options) { // Build up the group for the $group aggregation phase if(Array.isArray(options.sum)) { options.sum.forEach(function(opt) { - self.group[opt] = { '$sum': '$' + opt }; + self.group[opt.replace(/\./g,"-")] = { '$sum': '$' + opt }; }); } if(Array.isArray(options.average)) { options.average.forEach(function(opt) { - self.group[opt] = { '$avg': '$' + opt }; + self.group[opt.replace(/\./g,"-")] = { '$avg': '$' + opt }; }); } if(Array.isArray(options.min)) { options.min.forEach(function(opt) { - self.group[opt] = { '$min': '$' + opt }; + self.group[opt.replace(/\./g,"-")] = { '$min': '$' + opt }; }); } if(Array.isArray(options.max)) { options.max.forEach(function(opt) { - self.group[opt] = { '$max': '$' + opt }; + self.group[opt.replace(/\./g,"-")] = { '$max': '$' + opt }; }); } };