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

Switching collection at runtime, stores in unexpected collection

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

      When switching from collection at runtime, some documents, don't get stored in the expected collection.

      I've got this problem in multiple documents with a include (ActiveSupport::Concern based).
      And it happens most of the time when calling macros. (field doesn't seem to have this effect.)

      > Persisting using with is a one time switch in the persistence context - it changes back to its defaults immediately after.

      I've seen this section in the documentation, but this doesn't seems to be the problem.


      With Mongoid::Versioning included

      Unable to find source-code formatter for language: `. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
       ruby
      class Person
        include Mongoid::Document
        include Mongoid::Versioning
        field :name, type: String
      end
      
      # run
      p = Person.new(name: "johnmalkovich")
      p.with(collection: "acme.persons").save!
      

      `

      Expected results to be stored in collection acme.persons instead stored into people


      Removing the include Mongoid::Versioning solves this issue.

      Unable to find source-code formatter for language: `. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
       ruby
      class Person
        ...
        # include Mongoid::Versioning
        ...
      end
      
      
      # run
      p = Person.new(name: "johnmalkovich")
      p.with(collection: "acme.persons").save!
      
      

      `

      Result stored in collection acme.persons


      Used development Rails application, and stand-alone test-environment.

      Unable to find source-code formatter for language: `. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
        * rails (3.2.11)
        * activemodel (3.2.11)
        * activesupport (3.2.11)
        * mongoid (3.0.19)
        * moped (1.3.2)
        * origin (1.0.11)
      

      `

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

              Created:
              Updated:
              Resolved: