Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-13536

WriteResult only mentions the last insert if inserts happen in a for loop

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 2.6.0
    • Component/s: Shell
    • Labels:
      None
    • ALL
    • Hide
      > for( i = 1 ; i <= 10 ; i++ ) { for( j = 1; j <= 10 ; j++ ) { for( k = 1 ; k <= 10 ; k++ ) { db.foo.insert( { a : i , b : j , c : k } ) } } }
      WriteResult({ "nInserted" : 1 })
      

      Expected result: 1,000 documents are inserted, and WriteResult(

      { "nInserted" : 1000 }

      )

      Actual result: 1,000 documents are inserted (good) but WriteResult(

      { "nInserted" : 1 }

      ) is displayed, implying that we've only added one document to the collection.

      Show
      > for ( i = 1 ; i <= 10 ; i++ ) { for ( j = 1; j <= 10 ; j++ ) { for ( k = 1 ; k <= 10 ; k++ ) { db.foo.insert( { a : i , b : j , c : k } ) } } } WriteResult({ "nInserted" : 1 }) Expected result: 1,000 documents are inserted, and WriteResult( { "nInserted" : 1000 } ) Actual result: 1,000 documents are inserted (good) but WriteResult( { "nInserted" : 1 } ) is displayed, implying that we've only added one document to the collection.

      If I have a for loop that inserts documents in the shell, only the last insert will give a WriteResult.

      This is confusing because LOTS of documents may have been inserted, yet all we see is WriteResult: 1.

            Assignee:
            Unassigned Unassigned
            Reporter:
            william.cross William Cross
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: