Tag: mapreduce

查询Mongoid / rails 3中的嵌入对象(“低于”,Min运算符和排序)

我正在使用带有mongoid的rails 3。 我有一个股票的集合与嵌入的价格集合: class Stock include Mongoid::Document field :name, :type => String field :code, :type => Integer embeds_many :prices class Price include Mongoid::Document field :date, :type => DateTime field :value, :type => Float embedded_in :stock, :inverse_of => :prices 我想得到自给定日期以来最低价格低于给定价格p的股票,然后能够对每种股票的价格进行排序。 但看起来Mongodb不允许这样做。 因为这不起作用: @stocks = Stock.Where(:prices.value.lt => p) 此外,似乎mongoDB无法对嵌入对象进行排序。 那么,有没有替代方案来完成这项任务? 也许我应该将所有内容放在一个集合中,以便我可以轻松运行以下查询: @stocks = Stock.Where(:prices.lt => p) 但我真的想在我的查询之后得到按股票名称分组的结果(例如,具有一系列有序价格的不同股票)。 […]