-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fd270c3
commit c515f26
Showing
2 changed files
with
40 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10244,7 +10244,7 @@ moment.fn.within = function(range) { | |
|
||
/* global chatty */ | ||
|
||
chatty('\033[1;32m+ MongoDB Shell Extensions (0.2.4) by Gabriele Lana <[email protected]>\033[0m') | ||
chatty('\033[1;32m+ MongoDB Shell Extensions (0.2.5) by Gabriele Lana <[email protected]>\033[0m') | ||
|
||
DBCollection.prototype.last = function(n) { | ||
return this.find().sort({_id: -1}).limit(n || 1) | ||
|
@@ -10401,11 +10401,45 @@ DBCollection.prototype.distinctAndCount = function(field, query) { | |
|
||
var result = it.result || it.toArray() | ||
return _.reduce(result, function(all, r) { | ||
if (!_.any(r.values, isObject)) { | ||
all[_.values(r.values).join(',')] = r.count | ||
return all | ||
|
||
var isValidValue = | ||
_(r.values) | ||
.chain() | ||
.values() | ||
.any(function(value) { | ||
if (_(value).isArray()) { | ||
return _(value).all(function(value) { | ||
return !_(value).isObject() | ||
}) | ||
} | ||
// we support values like Number or Date but not {} | ||
return value.constructor.name !== '' | ||
}) | ||
.valueOf() | ||
|
||
if (!isValidValue) { | ||
throw 'distinctAndCount could not work when one or more fields are objects: ' + tojson(r.values) | ||
} | ||
throw 'distinctAndCount fields could not be objects: ' + tojson(r.values) | ||
|
||
var key = | ||
_(r.values) | ||
.chain() | ||
.values() | ||
.map(function(value) { | ||
if (_(value.valueOf).isFunction()) { | ||
value = value.valueOf() | ||
} | ||
if (_(value).isArray()) { | ||
value = _(value).sort().valueOf() | ||
} | ||
return value | ||
}) | ||
.valueOf() | ||
.join(',') | ||
|
||
all[key] = (all[key] || 0) + r.count | ||
|
||
return all | ||
}, {}) | ||
} | ||
|
||
|