【发布时间】:2013-05-10 21:15:47
【问题描述】:
我希望根据最后嵌入的Notificationdocument 中的字段查找Order 文档。
在下面的示例中,我希望找到所有嵌入了一个或多个notifications 的pending orders,并且最后一个notification 的datetime 存在5 到10 天。
我在这里的建议似乎没有奏效......:
Order.where(status: 'pending').gte('notifications.last.datetime' => 5.days.ago).lte('notifications.last.datetime' => 10.days.ago)
这是两个模型:
class Order
include Mongoid::Document
field :datetime, type: DateTime
field :status, type: String, default: 'pending'
embeds_many :notifications, :inverse_of => :order
end
class Notification
include Mongoid::Document
field :datetime, type: DateTime
embedded_in :order, :inverse_of => :notifications
end
【问题讨论】: