@@ -31,16 +31,16 @@ var Mongo = function (opts) {
3131
3232Mongo . prototype . command = function ( command , callback ) {
3333 var self = this ;
34- var exec_command = 'mongo ' ;
34+ var exec_command = 'mongo' ;
3535
3636 return Promise . resolve ( ) . then ( function ( ) {
37- var params = _ . reduce ( self . driver , function ( result , value , key ) {
37+ var params = _ . reduce ( self , function ( result , value , key ) {
3838 result += util . format ( '--%s %s ' , key , value ) ;
3939 return result ;
4040 } , '' ) ;
4141
42- exec_command += util . format ( ' %s --eval"%s"' , params , command ) ;
43- console . log ( 'exec_command =' , exec_command ) ;
42+ exec_command += util . format ( ' %s --eval "%s"' , params , command ) ;
43+ // console.log('exec_command =', exec_command);
4444
4545 var exec_options = {
4646 env : {
@@ -49,7 +49,6 @@ Mongo.prototype.command = function (command, callback) {
4949 EDITOR : process . env . EDITOR ,
5050 HOMEDRIVE : process . env . HOMEDRIVE ,
5151 HOMEPATH : process . env . HOMEPATH ,
52- PATH : process . env . PATH ,
5352 DEBUG : ''
5453 }
5554 } ;
@@ -83,6 +82,24 @@ var extractResult = function (result) {
8382 var lines = obj [ 0 ] . split ( os . EOL ) ;
8483 resultp . lines = lines ;
8584
85+ try {
86+ var tempArray = lines . splice ( 2 ) ;
87+ //console.log('tempArray', tempArray);
88+
89+ var jsonString = tempArray . reduce ( function ( previousValue , currentValue ) {
90+ var cleaned = cleanJsonDate ( currentValue . trim ( ) ) ;
91+ return previousValue + cleaned ;
92+ } , '' ) ;
93+ //console.log('jsonString', jsonString);
94+ resultp . object = JSON . parse ( jsonString ) ;
95+
96+
97+ } catch ( e ) {
98+ resultp . error = e ;
99+ }
100+
101+
102+
86103 return resultp ;
87104 }
88105 }
@@ -106,3 +123,30 @@ var extractResult = function (result) {
106123
107124 return result ;
108125} ;
126+
127+
128+ var cleanJsonDate = function ( line ) {
129+ if ( line . indexOf ( 'ISODate' ) > - 1 ) {
130+ var parts = line . split ( ':' ) ;
131+
132+ var re = / I S O D a t e \( " ( .* ) " / g;
133+ var str = line ;
134+ var m , value ;
135+
136+ while ( ( m = re . exec ( str ) ) !== null ) {
137+ if ( m . index === re . lastIndex ) {
138+ re . lastIndex ++ ;
139+ }
140+ // View your result using the m-variable.
141+ // eg m[0] etc.
142+ //console.log('m', m);
143+ value = m && m [ 1 ] ? m [ 1 ] : 'error' ;
144+ }
145+
146+ return util . format ( '%s : { "$date" : "%s" },' , parts [ 0 ] , value ) ;
147+ } else {
148+ return line ;
149+ }
150+
151+
152+ } ;
0 commit comments