简体   繁体   English

查询蒙古包和红宝石的集合

[英]Querying a collection with mongoid and ruby

I want to query many different collections from a model in rails. 我想从Rails模型中查询许多不同的集合。

For example: 例如:

class Statistics
  include Mongoid::Document
end

I want to be able to query a statistics or maybe a my_stats collection. 我希望能够查询统计数据或my_stats集合。 Is that possible? 那可能吗? How can I do it? 我该怎么做?

Your question isn't clear. 您的问题不清楚。 If you want to know how to define your own collection name, instead of having Mongoid auto-generate one via the class name/ActiveSupport, you can do that using the store_in method. 如果您想知道如何定义自己的集合名称,而不是让Mongoid通过类名称/ ActiveSupport自动生成一个集合名称,则可以使用store_in方法来实现。 Like so: 像这样:

class Statistics
  include Mongoid::Document
  store_in :mystats
end

If you're asking how to search multiple collections with one query, that isn't possible in MongoDB, as far as I'm aware. 据我所知,如果您要问如何用一个查询来搜索多个集合,那在MongoDB中是不可能的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM