如果数据类型是数组类型,我无法使用 rails 在 mongodb 中插入数据
以下是代码
def friend
Twitter.configure do |config|
config.consumer_key = 'GpCZ3ppx2tvOYB7mP4FONw'
config.consumer_secret = 'ectbzaP2oLPTSMGJaR5Fj6mmdgFyVsWeM9HoZ2iwaI'
config.oauth_token ='1378905500-TMtwUpl4bVpVDAcZQ29SVONITmFLL1aCzSLHDQQ'
config.oauth_token_secret = 'SIsfYHqSKfTEUD4dutaI7zYbfJQjxXmiNXiv4vWkfY'
end
@frend= Twitter.friends("shamshul2007")
@frend.each do |hell|
puts hell.name.inspect.to_s
end
#=====
fr=Array.new
@frend.each do |f|
fr.push(f)
end
#data insertion
@fri=Friend.new
@fri.username="shamshul2007"
@fri.friend=fr
@fri.save
end
模型是朋友.rb
class Friend
include Mongoid::Document
field :username, type: String
field :friend, type: Array
end
将数据推送到 mongodb 时出现以下错误
undefined method `__bson_dump__' for #<Twitter::User:0x007fbbec1a8538>