Skip to content

Commit 187c306

Browse files
committed
Update release package
1 parent 796addd commit 187c306

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

released/mongorc.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9834,19 +9834,29 @@ DBQuery.prototype.tojson = function() {
98349834
return tojson(this.toArray())
98359835
}
98369836

9837+
/* global isObject: false */
9838+
98379839
DBCollection.prototype.distinctAndCount = function(field, query) {
9840+
field = [].concat(field)
98389841
query = query || {}
98399842

9843+
var groupById = _([].concat(field)).reduce(function(result, key) {
9844+
result[key.replace('.', '_')] = '$' + key; return result
9845+
}, {})
9846+
98409847
var it = this.aggregate(
98419848
{$match: query},
9842-
{$group: {_id: '$' + field, count: {$sum: 1}}},
9843-
{$project: {name: '$_id', count: 1, _id: 0}}
9849+
{$group: {_id: groupById, count: {$sum: 1}}},
9850+
{$project: {values: '$_id', count: 1, _id: 0}}
98449851
)
98459852

98469853
if (it.ok === 1) {
98479854
return _.reduce(it.result, function(all, r) {
9848-
all[r.name] = r.count
9849-
return all
9855+
if (!_.any(r.values, isObject)) {
9856+
all[_.values(r.values).join(',')] = r.count
9857+
return all
9858+
}
9859+
throw 'distinctAndCount fields could not be objects: ' + tojson(r.values)
98509860
}, {})
98519861
}
98529862
return it

0 commit comments

Comments
 (0)