@@ -10244,7 +10244,7 @@ moment.fn.within = function(range) {
1024410244
1024510245/* global chatty */
1024610246
10247- chatty ( '\033[1;32m+ MongoDB Shell Extensions (0.2.2 ) by Gabriele Lana <gabriele.lana@gmail.com>\033[0m' )
10247+ chatty ( '\033[1;32m+ MongoDB Shell Extensions (0.2.3 ) by Gabriele Lana <gabriele.lana@gmail.com>\033[0m' )
1024810248
1024910249DBCollection . prototype . last = function ( n ) {
1025010250 return this . find ( ) . sort ( { _id : - 1 } ) . limit ( n || 1 )
@@ -10370,7 +10370,7 @@ DBCollection.prototype.distinctAndCount = function(field, query) {
1037010370 query = query || { }
1037110371
1037210372 var groupById = _ ( [ ] . concat ( field ) ) . reduce ( function ( result , key ) {
10373- result [ key . replace ( '.' , '_' ) ] = '$' + key ; return result
10373+ result [ key . replace ( / \. / g , '_' ) ] = '$' + key ; return result
1037410374 } , { } )
1037510375
1037610376 var it = this . aggregate (
@@ -10379,16 +10379,19 @@ DBCollection.prototype.distinctAndCount = function(field, query) {
1037910379 { $project : { values : '$_id' , count : 1 , _id : 0 } }
1038010380 )
1038110381
10382- if ( it . ok === 1 ) {
10383- return _ . reduce ( it . result , function ( all , r ) {
10384- if ( ! _ . any ( r . values , isObject ) ) {
10385- all [ _ . values ( r . values ) . join ( ',' ) ] = r . count
10386- return all
10387- }
10388- throw 'distinctAndCount fields could not be objects: ' + tojson ( r . values )
10389- } , { } )
10382+ var resultIsAnObject = ( it . result !== undefined ) && ( it . ok !== undefined )
10383+ if ( resultIsAnObject && it . ok === 0 ) {
10384+ return it
1039010385 }
10391- return it
10386+
10387+ var result = it . result || it . toArray ( )
10388+ return _ . reduce ( result , function ( all , r ) {
10389+ if ( ! _ . any ( r . values , isObject ) ) {
10390+ all [ _ . values ( r . values ) . join ( ',' ) ] = r . count
10391+ return all
10392+ }
10393+ throw 'distinctAndCount fields could not be objects: ' + tojson ( r . values )
10394+ } , { } )
1039210395}
1039310396
1039410397DBQuery . prototype . select = function ( expression ) {
0 commit comments