Skip to content

Commit

Permalink
Release 0.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielelana committed Nov 10, 2014
1 parent 8a1cad6 commit 461bf40
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mongodb-shell-extensions",
"version": "0.2.2",
"version": "0.2.3",
"description": "Useful MongoDB shell extensions",
"files": [
"src",
Expand Down
25 changes: 14 additions & 11 deletions released/mongorc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10244,7 +10244,7 @@ moment.fn.within = function(range) {

/* global chatty */

chatty('\033[1;32m+ MongoDB Shell Extensions (0.2.2) by Gabriele Lana <[email protected]>\033[0m')
chatty('\033[1;32m+ MongoDB Shell Extensions (0.2.3) by Gabriele Lana <[email protected]>\033[0m')

DBCollection.prototype.last = function(n) {
return this.find().sort({_id: -1}).limit(n || 1)
Expand Down Expand Up @@ -10370,7 +10370,7 @@ DBCollection.prototype.distinctAndCount = function(field, query) {
query = query || {}

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

var it = this.aggregate(
Expand All @@ -10379,16 +10379,19 @@ DBCollection.prototype.distinctAndCount = function(field, query) {
{$project: {values: '$_id', count: 1, _id: 0}}
)

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

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
}
throw 'distinctAndCount fields could not be objects: ' + tojson(r.values)
}, {})
}

DBQuery.prototype.select = function(expression) {
Expand Down

0 comments on commit 461bf40

Please sign in to comment.