简体   繁体   中英

Querying a collection with mongoid and ruby

I want to query many different collections from a model in rails.

For example:

class Statistics
  include Mongoid::Document
end

I want to be able to query a statistics or maybe a my_stats collection. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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