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

calling #first then iterating over a cursor has unexpected results

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

      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

            Assignee:
            kbanker Kyle Banker
            Reporter:
            aarnell Alex Arnell
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: