Hello, I'm wondering if there is something fundamentally wrong with the model design below. When we try to add 1,000 instances of the
embedded document to the history collection in the document, the spec test receives a "stack level too deep" at about 100 items.
require 'mongomodel'
module MyModule
# Provides a model of game player constructs.
class Player < MongoModel::Document
# Provides the history for the player.
class History < MongoModel::EmbeddedDocument
property :instance_id, String, :unique => true, :required => true
property :when_started, Date, :default => Date.today
property :play_duration, Integer, :default => 0
property :play_metrics, String
belongs_to :history, :class => Player
end
property :player_id, String, :index => true, :unique => true, :required => true
property :level, String
property :preferences, String
property :history, Collection[History], :default => History.new
timestamps!
validates_presence_of :player_id
end
end
player = MyModule::Player.find_by_player_id(player_id)
if player.nil?
error 404, "Player not found: " + player_id
end
# create and populate a new instance
body = Yajl::Parser.parse(request.body.read)
values = body['history'][0]
hi = MyModule::Player::History.new
hi.instance_id = values['instance_id']
...set other fields...
player.history << hi
player.save!
This seems to work fine for the first few dozen entries, but fails later. Ruby 1.8.7 on Mac OS X. Is there something missing from the model or is the update done incorrectly?