Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-1848

Collection#find must be invoked with a block when timeout is disabled

    • Type: Icon: Task Task
    • Resolution: Done
    • 2.4.8
    • Affects Version/s: None
    • Component/s: None

      I was trying to disable the timeout on the Mongo::Cursor class and the suggested approach (by them as well as in the mongoid google groups) is to invoke the #find method and pass the block (until the newer mongoid is out which take care of this stuff for us).

      So I tried:

      class Apple
        include Mongoid::Document
        field :color, type: String
      end
      
      Apple.create(color: "red")
      
      Apple.collection.find({}, :timeout => false) do |c|
        puts "cursor: #{c}"
      end
      

      This gives the error: Collection#find must be invoked with a block when timeout is disabled

      However, if I drop to the Mongo ruby drive "Collection" class (Mongo::Collection) it works:

      Apple.collection.driver.find({}, :timeout => false) do |c|
        puts "worked!"
      end
      

      Is this the expected behavior? It seems like I should be able to call find on the collection but maybe that wasn't the intention, hence the "driver" which gives access to the raw Mongo::Collection. Just thought I'd mention this in case it is a bug and not "as designed" (it burned me for a little while).

            Assignee:
            Unassigned Unassigned
            Reporter:
            mindscratch mindscratch
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: