是否可以执行查询并返回嵌入的文档?
目前,我有:
class Post
include MongoMapper::Document
many :comments
end
class Comment
include MongoMapper::EmbeddedDocument
belongs_to :post
key :author
key :date
key :body
end
这是一个几乎存在的查询:
Post.all("comments.date" => {"$gt" => 3.days.ago})
这将返回所有帖子对象,但不返回评论。我想我可以做类似的事情:
Post.all("comments.date" => {"$gt" => 3.days.ago}).map(&:comments)
但这将返回帖子中的所有评论。我想获得所有符合此条件的评论。也许Comment
不应该嵌入。