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

mongoid seeds database but cannot find data in database

    XMLWordPrintableJSON

Details

    • Icon: Task Task
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • 12_01_17
    • 4.0.0 final
    • None
    • None
    • Ubuntu 14.04

    Description

      Mongoid works fine on development in a Rails 4 app. However, when I seed my staging environment, the seed does not fail (so I assume Mongoid creates the objects) but when I look at the mongo database on staging no objects are created.

      I run the following to seed:

      RAILS_ENV=staging bundle exec rake db:seed

      In seeds.rb, I have this:

      [Role, User, FieldType].each do |model|
      puts "seeding #

      {model.name}

      "
      model.seed
      end

      The ActiveRecord objects are seeded (Role and User) but not the Mongoid object (FieldType). FieldType looks like this:

      class FieldType
      include Mongoid::Document
      field :name
      def self.seed
      find_or_create_by(name: 'Text')
      find_or_create_by(name: 'Number')
      end
      end

      The seed never fails and it seems that it creates the FieldType objects. In my mongoid.yml I have the following:

      staging:
      sessions:
      default:
      database: core_staging
      hosts:

      • localhost:27017
        options:

      But when I log into my staging server, no core_staging was ever created with the objects.

      Why is this happening? Is this a bug or am I missing something from the mongoid.yml? If I am missing something from mongoid.yml that I am not aware of, then I will close this issue.

      Attachments

        Activity

          People

            Unassigned Unassigned
            johnmerlino John Merlino
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: