나는 웹상에서 내 문제에 대한 해결책을 찾고 있었다. MongoDB를 사용하여 MongoDB에 데이터 집합을 작성합니다. 나는 다음과 같이 mongoid으로 배치 삽입 할 노력하고있어복잡한 스키마가있는 몽고 이드 배치 삽입?
:
class Geonode
include Mongoid::Document
include Mongoid::Timestamps
embeds_one :location
embeds_one :transport
end
class Location
include Mongoid::Document
field :city, :type => String
embedded_in :geonode
end
class Transport
include Mongoid::Document
embeds_many :trainstation
embedded_in :geonode
end
class Trainstation
include Mongoid::Document
field :station, :type => String
belongs_to :transport
end
을 그리고 그것은 하나 그것을 하나를 수행 잘 작동하지만 난 배치로 많은, 내가 무엇을 원하는 경우 해야 할 것?
나는 시도했다.
require 'moped'
require 'rubygems'
require 'mongo'
require 'mongoid'
require 'skySchema.rb' #schema is the file i defined the classes just before
Mongoid.load!("./mongoid.yml", :development)
include Mongo
batch = []
batch << {:location => Location.new(:city => "London"),
:transport => Transport.new(:trainstation =>
[Trainstation.new(:station => "Kings Cross")])}}
and then doing this many many times, after which
Geonode.collection.insert(batch)
그러나 작동하지 않습니다. 내가 뭐 잘못하고 있니?
Geonode.insert(batch)
그리고 다른 방법으로 배치를 포맷 :
"작동하지 않는다"는 의미는 무엇입니까? 너 오류가있어? 첫 번째 것만 삽입됩니까? 다른 것? –
개체가 삽입되지 않고 충돌합니다. 그리고 다른 것을 정의해야하는지 궁금하네요? 아무런 문제가 발생하지 않습니다. .rvm/gems/ruby-1.9.3-p429/gems/mongoid-3.1.4/lib/mongoid/attributes.rb : 320 :'method_missing '에서 : 정의되지 않은 메소드 # (NoMethodError)에 대한 '__bson_dump__' –
inquire
Mongoid의 버전은 무엇입니까? MongoDB 드라이버가 배치 삽입 구문을 항상 지원하지는 않았으므로 이전 버전의 Ruby 드라이버 버전을 기반으로 할 수 있습니까? –