@@ -10244,7 +10244,7 @@ moment.fn.within = function(range) {
1024410244
1024510245/* global chatty */
1024610246
10247- chatty ( '\033[1;32m+ MongoDB Shell Extensions (0.2.3 ) by Gabriele Lana <gabriele.lana@gmail.com>\033[0m' )
10247+ chatty ( '\033[1;32m+ MongoDB Shell Extensions (0.2.4 ) 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 )
@@ -10303,38 +10303,53 @@ var printcsv = function(x) {
1030310303 } )
1030410304}
1030510305
10306- var tocsv = function ( x ) {
10307- var lines = [ ] ,
10308- fieldNames = { } ,
10309- encodedDocuments = x . map ( function ( doc ) {
10310- return _ . reduce ( doc , function ( values , value , field ) {
10311- fieldNames [ field ] = true
10312- values [ field ] = tojson ( value ) . replace (
10313- / ^ (?: I S O D a t e | O b j e c t I d ) \( ( .* ) \) $ / ,
10314- function ( _ , contentAsString ) {
10315- return contentAsString
10316- }
10317- )
10318- return values
10319- } , { } )
10320- } )
10321-
10322- fieldNames = _ . keys ( fieldNames )
10306+ var tocsv = ( function ( ) {
10307+ var flatten = function ( o ) {
10308+ return _ . reduce ( o , function ( flattened , value , field ) {
10309+ if ( _ . isPlainObject ( value ) ) {
10310+ _ . forEach ( flatten ( value ) , function ( nestedValue , nestedField ) {
10311+ flattened [ [ field , nestedField ] . join ( '.' ) ] = nestedValue
10312+ } )
10313+ } else {
10314+ flattened [ field ] = value
10315+ }
10316+ return flattened
10317+ } , { } )
10318+ }
1032310319
10324- lines . push ( fieldNames . join ( ',' ) )
10325- encodedDocuments . forEach ( function ( encodedDocument ) {
10326- lines . push (
10327- fieldNames . map ( function ( fieldName ) {
10328- if ( encodedDocument [ fieldName ] !== undefined ) {
10329- return encodedDocument [ fieldName ]
10330- }
10331- return '""'
10332- } ) . join ( ',' )
10333- )
10334- } )
10320+ return function ( x ) {
10321+ var lines = [ ] ,
10322+ fieldNames = { } ,
10323+ encodedDocuments = x . map ( function ( doc ) {
10324+ return _ . reduce ( flatten ( doc ) , function ( values , value , field ) {
10325+ fieldNames [ field ] = true
10326+ values [ field ] = tojson ( value ) . replace (
10327+ / ^ (?: I S O D a t e | O b j e c t I d ) \( ( .* ) \) $ / ,
10328+ function ( _ , contentAsString ) {
10329+ return contentAsString
10330+ }
10331+ )
10332+ return values
10333+ } , { } )
10334+ } )
10335+
10336+ fieldNames = _ . keys ( fieldNames )
10337+
10338+ lines . push ( fieldNames . join ( ',' ) )
10339+ encodedDocuments . forEach ( function ( encodedDocument ) {
10340+ lines . push (
10341+ fieldNames . map ( function ( fieldName ) {
10342+ if ( encodedDocument [ fieldName ] !== undefined ) {
10343+ return encodedDocument [ fieldName ]
10344+ }
10345+ return ''
10346+ } ) . join ( ',' )
10347+ )
10348+ } )
1033510349
10336- return new CSV ( lines )
10337- }
10350+ return new CSV ( lines )
10351+ }
10352+ } ) ( )
1033810353
1033910354DBQuery . prototype . reverse = function ( ) {
1034010355 if ( ! this . _query . query || _ . isEmpty ( this . _query . query ) ) {
0 commit comments