【发布时间】:2013-03-10 07:57:59
【问题描述】:
我正在尝试通过其 id 搜索嵌入文档,并将其返回。这是可能的,但据我所知,只有通过使用 mongo 查找嵌入它的文档,然后在 ruby 中搜索该文档以查找我想要的嵌入文档。像这样:
# commenter.rb
def post
# todo: find syntax do avoid double query
if user = User.any_of({'posts.commenter_ids' => self.id}).last
user.posts.where('commenter_ids' => self.id).last
end
end
看起来很简单,但我在 google/SO 搜索中没有找到我喜欢的任何东西。
想法?
【问题讨论】:
-
能否提供您的模型?
标签: ruby-on-rails mongodb mongoid