Skip to content

Commit

Permalink
Update release package
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielelana committed Aug 5, 2014
1 parent 796addd commit 187c306
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions released/mongorc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9834,19 +9834,29 @@ DBQuery.prototype.tojson = function() {
return tojson(this.toArray())
}

/* global isObject: false */

DBCollection.prototype.distinctAndCount = function(field, query) {
field = [].concat(field)
query = query || {}

var groupById = _([].concat(field)).reduce(function(result, key) {
result[key.replace('.', '_')] = '$' + key; return result
}, {})

var it = this.aggregate(
{$match: query},
{$group: {_id: '$' + field, count: {$sum: 1}}},
{$project: {name: '$_id', count: 1, _id: 0}}
{$group: {_id: groupById, count: {$sum: 1}}},
{$project: {values: '$_id', count: 1, _id: 0}}
)

if (it.ok === 1) {
return _.reduce(it.result, function(all, r) {
all[r.name] = r.count
return all
if (!_.any(r.values, isObject)) {
all[_.values(r.values).join(',')] = r.count
return all
}
throw 'distinctAndCount fields could not be objects: ' + tojson(r.values)
}, {})
}
return it
Expand Down

0 comments on commit 187c306

Please sign in to comment.