@@ -444,33 +444,25 @@ class Import : public Tool {
444444 char * line = buffer.get ();
445445
446446 if (_jsonArray) {
447- while ( _jsonArray || in-> rdstate () == 0 ) {
447+ while (true ) {
448448 try {
449449 BSONObj o;
450- if (_jsonArray) {
451- int bytesProcessed = 0 ;
452- if (line == buffer.get ()) { // Only read on first pass - the whole array must be on one line.
453- bytesProcessed = getLine (in, line);
454- line += bytesProcessed;
455- len += bytesProcessed;
456- }
457- if ((bytesProcessed = parseJSONArray (line, o)) < 0 ) {
458- len += bytesProcessed;
459- break ;
460- }
461- len += bytesProcessed;
450+
451+ int bytesProcessed = 0 ;
452+ if (line == buffer.get ()) { // Only read on first pass - the whole array must be on one line.
453+ bytesProcessed = getLine (in, line);
462454 line += bytesProcessed;
455+ len += bytesProcessed;
463456 }
464- else {
465- if (!parseRow (in, o, len)) {
466- continue ;
467- }
457+ if ((bytesProcessed = parseJSONArray (line, o)) < 0 ) {
458+ len += bytesProcessed;
459+ break ;
468460 }
461+ len += bytesProcessed;
462+ line += bytesProcessed;
469463
470- if ( _headerLine ) {
471- _headerLine = false ;
472- }
473- else if (_doimport) {
464+ // Import documents
465+ if (_doimport) {
474466 importDocument (ns, o);
475467
476468 if (num < 10 ) {
@@ -488,8 +480,9 @@ class Import : public Tool {
488480 log () << line << endl;
489481 errors++;
490482
491- if (hasParam (" stopOnError" ) || _jsonArray)
492- break ;
483+ // Since we only support JSON arrays all on one line, we might as well stop now
484+ // because we can't read any more documents
485+ break ;
493486 }
494487
495488 if ( pm.hit ( len + 1 ) ) {
@@ -498,27 +491,12 @@ class Import : public Tool {
498491 }
499492 }
500493 else {
501- while ( _jsonArray || in->rdstate () == 0 ) {
494+ while (in->rdstate () == 0 ) {
502495 try {
503496 BSONObj o;
504- if (_jsonArray) {
505- int bytesProcessed = 0 ;
506- if (line == buffer.get ()) { // Only read on first pass - the whole array must be on one line.
507- bytesProcessed = getLine (in, line);
508- line += bytesProcessed;
509- len += bytesProcessed;
510- }
511- if ((bytesProcessed = parseJSONArray (line, o)) < 0 ) {
512- len += bytesProcessed;
513- break ;
514- }
515- len += bytesProcessed;
516- line += bytesProcessed;
517- }
518- else {
519- if (!parseRow (in, o, len)) {
520- continue ;
521- }
497+
498+ if (!parseRow (in, o, len)) {
499+ continue ;
522500 }
523501
524502 if ( _headerLine ) {
@@ -542,7 +520,7 @@ class Import : public Tool {
542520 log () << line << endl;
543521 errors++;
544522
545- if (hasParam (" stopOnError" ) || _jsonArray )
523+ if (hasParam (" stopOnError" ))
546524 break ;
547525 }
548526
0 commit comments