【发布时间】:2012-05-02 21:33:42
【问题描述】:
我已阅读 mongoid 文档,但对我正确理解如何正确索引嵌入文档感到不自信。请看一下这个小代码 sn-p,如果我走在正确的轨道上,请告诉我!
标准
temp = Array.new
temp.push(BSON::ObjectId("some_bson_objecId"))
temp.push(BSON::ObjectId("some_other_bson_objecId"))
Game.any_of({'players.user_id' => @user.id},{:_id => temp})
游戏模型
embeds_many :players
index(
[
[ "players.user_id" ],
[ "players.user_name" ]
],
unique: true
)
玩家模型
embedded_in :game
field :user_id, :type => BSON::ObjectId
field :user_name, :type => String, :default => ""
index(
[
[ :user_id ],
[ :user_name ]
],
unique: true
)
【问题讨论】:
标签: mongoid