I have started working with mongoid gem but I am getting an Uninitialized constant error

I have defined a document Tweet

class Tweet
  include Mongoid::Document
  field :tweet_id, type: Int  
  field :created_at, type: DateTime
  field :text, type: String         
  field :user_id, type: Int       

  embedded_in :user  
end

Another document User

class User
  include Mongoid::Document
  field :name, type: String
  field :screen_name, type: String
  field :user_id, type: Int

  embeds_many :tweets    
end

I want to write a rake task to create and insert tweets into database. Code for the rake task

I have tweets stored in a file whose path is @pathtofile

task :readtweet => :environment do
    File.readlines(@pathtofile).each do |line|
        line=line.chomp()
        tweet_hash = JSON.parse(line)
        Tweet.new(created_at: my_hash['created_at'], text: my_hash['text'] )         
    end
end

But every time i execute the rake task it gives me error.

uninitialized constant Tweet::Int
/home/c0mrade/testapp/app/models/tweet.rb:4:in `<class:Tweet>'
/home/c0mrade/testapp/app/models/tweet.rb:2:in `<top (required)>'
/home/c0mrade/testsapp/lib/tasks/data.rake:22:in `block (3 levels) in <top (required)>'

I have followed the installation instructions on mongodb site

Can anybody help me with this error?

有帮助吗?

解决方案

Should it be Integer instead of Int? I don't know if this will fix your issue here but I didn't see Int in any of the docs (please correct me if I'm wrong).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top