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

uninitialized constant BSON::InvalidObjectId #14

Open
JudyWu opened this issue Oct 28, 2015 · 2 comments
Open

uninitialized constant BSON::InvalidObjectId #14

JudyWu opened this issue Oct 28, 2015 · 2 comments

Comments

@JudyWu
Copy link

JudyWu commented Oct 28, 2015

I am currently using Rails 4 and edited the config/routes.rb as below:

  Rails.application.routes.draw do
      devise_for :admin_users, ActiveAdmin::Devise.config
      ActiveAdmin.routes(self)

      namespace :admin do
          resources :users do
              resources :annotations
          end
          mount Rack::GridFS::Endpoint.new(:db => Mongoid::Config.sessions[:default]), :at => "gridfs",:lookup => :path
      end 
   end

But when I tried http://localhost:3000/admin/gridfs/54f5ece4e4b0e8f8dcce15d0, an error came up as "uninitialized constant BSON::InvalidObjectId". The same error came up when I tried http://localhost:3000/admin/gridfs. I got the id from the fs.files collection of the Mongodb.

Here is an example of an image in fs.files:

{ "_id" : ObjectId("55314ad2e4b08b15f51ddf65"), "metadata" : { "_id" :  "ced7ca7f-e287-45b5-a58b-70b9f397a253", "media_id" : "2ED3539B-E62B-4EA1-8224-3EE0DA8386E8.jpg", "data_point_id" : "1A48F01F-725F-49FD-A2A2-347D71910693", "size" : NumberLong(354010), "content_type" : "image/jpeg"}, "filename" : "ced7ca7f-e287-45b5-a58b-70b9f397a253", "aliases" : null, "chunkSize" : NumberLong(261120), "uploadDate" : ISODate("2015-04-17T18:02:58.880Z"), "length" : NumberLong(354010), "contentType" : "image/jpeg", "md5" : "e01669ddc1b26b48086ec1c700004f00" }

I am not sure what I have done wrong or what else I need to add in order for that to work.

Any help is appreciated and thank you very much!!! :)

@ches
Copy link
Collaborator

ches commented Nov 3, 2015

Hi Judy,

It's been a long while since we've updated this library, it's pretty likely that it isn't working with current versions of the Mongo Ruby driver and/or BSON lib, apologies.

I'm not using rack-gridfs currently, so it might be awhile before I get the chance to test and try to update the library myself, it might be faster to give it a shot yourself, I'll happily review patches to bring it up-to-date. For sure we ought to start with at least updating the rack-gridfs gemspec to declare that we're not compatible with your version of whatever library (apparently bson) is causing the issue. If you're using a version of Mongoid like 4.x that utilizes moped instead of the mongo gem, that could be a reason for discrepancy, because we never accounted for that in rack-gridfs.

Since you're using Mongoid, everything relevant is probably installed as a dependency of that and indented beneath it in your Gemfile.lock—would you mind sharing that portion of the lock file from your project? I'll try to backtrack to where the change that broke compatibility happened.

ches added a commit that referenced this issue Nov 3, 2015
Some historical versions of the mongo gem had an open-ended ">="
dep on bson (e.g. https://rubygems.org/gems/mongo/versions/1.3.0), so
users with one of these versions locked could end up getting
incompatible mongo 1.x and bson 2.x installed together.

References #14
@ches
Copy link
Collaborator

ches commented Nov 3, 2015

Could you please try a bundle update rack-gridfs? If you're using Mongoid 3.x or 4.x, and I suspect you are, I believe rack-gridfs 0.4.2 should resolve your issue, for now.

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