Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to specify a separate gridfs host? #68

Open
raulccabreu opened this issue Apr 16, 2017 · 1 comment
Open

How to specify a separate gridfs host? #68

raulccabreu opened this issue Apr 16, 2017 · 1 comment

Comments

@raulccabreu
Copy link

Instead of connect to the mongoid configured one (usually the used to store model documents).

This can be useful on cluster configurations with different number for files and documents hosts.

@syntruth
Copy link

syntruth commented Apr 3, 2018

I had to figure this out for myself as well, since the code is a bit less than clear on how to do this, but it is possible, by giving the File and Chunk model a store_in hash.

gridfs = Mongoid::GridFs
gridfs.file_model.store_in database: 'db_name_here'
gridfs.chunk_model.store_in database: 'db_name_here'

This can then be confirmed with:

gridfs.file_model.collection

In my apps file model (in this case, for ActiveDirectory user photos), I have a convenience memoized set up method:

def self.gridfs
  @gridfs ||= begin
    gridfs = Mongoid::GridFs

    gridfs.file_model.store_in database: AD.database_name
    gridfs.chunk_model.store_in database: AD.database_name

    gridfs
  end
end

So far, that seems to work, allowing me to store those files in a single database, but access them from 3 separate web-apps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants