Uploaded image for project: 'Ruby Driver'
  1. Ruby Driver
  2. RUBY-108

calling #first then iterating over a cursor has unexpected results

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: 12_01_17
    • Component/s: None
    • Labels:
      None

      Description

      If you have a collection, "test" containing 3 documents.

      test = db.collection('test')
      test.insert(

      { 'a' => 1 }

      )
      test.insert(

      { 'b' => 1 }

      )
      test.insert(

      { 'c' => 1 }

      )

      cursor = test.find
      puts cursor.count

      1. => 3

      puts cursor.first

      1. => { '_id' => ..., 'a' => 1}

      cursor.each do |doc|
      puts doc
      end

      1. => { '_id' => ..., 'b' => 1 }
      2. => { '_id' => ..., 'c' => 1 }

      I would expect the call to #first to be non-destructive so that a later iteration returns all 3 documents.

      A possible to workaround is to use each_with_index and checking if the index == 0

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: