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

Inconsistencies with dynamic collections

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 12_01_17
    • Component/s: None
    • Labels:

      Description

      I have noticed inconsistent behaviour when using the

      (collection: collection_name)

      modifier to force mongoid to read from / write to a different collection.

      First of all this doesn't work as expected:

      Search.with(collection: "search_collection_1").where(...)
      

      doesn't work. Instead you need to add

       to make it work, like:
      

      ruby
      Search.all.with(collection: "search_collection_1").where(...)

       
      Furthermore, when I create a new object with 

      with

       then consequent updates to the object use the correct collection, i.e:
      

      ruby
      search = Search.with(collection: "search_collection_1").create(id: "xyz", data1: "some useful data...")
      search.inc(usage: 1) # this will update the document in the correct collection

       
      However during retrieval this is not the case:
      

      ruby
      search = Search.with(collection: "search_collection_1").where(id: "xyz").first
      search.inc(usage: 1) # this will update the document in the default "searches" collection (practically it will do nothing, since the document is not there)

      search.with(collection: "search_collection_1")
      search.inc(usage: 2) # now it use the proper collection
      `

      Is this something that will be fixed?
      Or is it supposed to work like this?

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved: