mongoid / mongoid-grid_fs

A pure Mongoid/Moped implementation of the MongoDB GridFS specification.
Other
83 stars 50 forks source link

Files don't get stored to a custom namespace #11

Closed abhas closed 10 years ago

abhas commented 11 years ago

I tried creating a custom namespace as follows:

image = GridFs.namespace(:image)
f = image.put("photo.png")

So f returns a GridFS::Image::File object the way I would expect. Now, when I go back to the mongo shell, I see that there are two new collections: image.chunks and image.files. However the file I uploaded is missing.

Is there anything else that I need to do to get the file to be stored in this custom namespace?

rmm5t commented 11 years ago

@abhas, Is this still a problem? If so, would you mind putting together a failing test case that exposes the problem?

abhas commented 11 years ago

Hi Ryan, honestly I've not checked recently. I went back to using Mongoid 2.5.x and the corresponding grid_fs gem. Let me try this out again and if I face the same problem again.

rmm5t commented 11 years ago

@abhas Any time to follow-up on this?

abhas commented 11 years ago

Sorry for the delay in following up. I am still not able to get custom namespaces to work. Is there something that I could be doing wrong here?

1.9.3 (main):0 > gridfs = Mongoid::GridFs
=> Mongoid::GridFS < Object
1.9.3 (main):0 > gridfs.namespace = "test"
=> "test"
1.9.3 (main):0 > gridfs.put(File.open("/etc/motd"))
  MOPED: 127.0.0.1:27017 INSERT       database=letshelp collection=fs.chunks documents=[{"_id"=>"519462ff00de2c44b6000002", "n"=>0, "files_id"=>"519462ff00de2c44b6000001", "data"=>#<Moped::BSON::Binary type=:generic length=98>}] flags=[] (0.3710ms)
  MOPED: 127.0.0.1:27017 QUERY        database=letshelp collection=fs.files selector={:filename=>"519462ff00de2c44b6000001/motd"} flags=[] limit=1 skip=0 batch_size=nil fields={:_id=>1} (0.5369ms)
  MOPED: 127.0.0.1:27017 INSERT       database=letshelp collection=fs.files documents=[{"_id"=>"519462ff00de2c44b6000001", "contentType"=>"application/octet-stream", "length"=>98, "chunkSize"=>4194304, "uploadDate"=>2013-05-16 04:39:27 UTC, "md5"=>"338b819cbad7c7d26ff127e162c4e23b", "filename"=>"519462ff00de2c44b6000001/motd", "chunkLength"=>1}] flags=[] (0.2003ms)
=> #<Mongoid::GridFS::Fs::File:0x00000005e80030> {
          :_id => "519462ff00de2c44b6000001",
  :chunkLength => 1,
    :chunkSize => 4194304,
  :contentType => "application/octet-stream",
     :filename => "519462ff00de2c44b6000001/motd",
       :length => 98,
          :md5 => "338b819cbad7c7d26ff127e162c4e23b",
   :uploadDate => 2013-05-16 04:39:27 UTC
}
1.9.3 (main):0 > gridfs.namespace
=> "test"
rmm5t commented 11 years ago

@abhas Hi. Sorry, I haven't played with the custom namespacing; I haven't had a need for it yet.

If there is an underlying issue, what would really help is a pull-request with at least a failing test case that we can use to try and work off of.

rmm5t commented 10 years ago

@abhas Try this:

mongoid_grid_fs:001:0> image = Mongoid::GridFs.build_namespace_for(:image)
=> Mongoid::GridFs::Image
mongoid_grid_fs:002:0> image.put("image.jpg")
=> #<Mongoid::GridFs::Image::File _id: 53429609c2e4dc40bd000001, length: 435881, chunkSize: 4194304, uploadDate: 2014-04-07 12:11:53 UTC, md5: "c5c8e136036276acbf6934b740b92eef", filename: "53429609c2e4dc40bd000001/image.jpg", contentType: "image/jpeg", aliases: nil>
mongoid_grid_fs:003:0> image.find("53429609c2e4dc40bd000001/image.jpg")
=> #<Mongoid::GridFs::Image::File _id: 53429609c2e4dc40bd000001, length: 435881, chunkSize: 4194304, uploadDate: 2014-04-07 12:11:53 UTC, md5: "c5c8e136036276acbf6934b740b92eef", filename: "53429609c2e4dc40bd000001/image.jpg", contentType: "image/jpeg", aliases: nil>
ahoward commented 10 years ago

@abhas there is an example in the tests -> https://github.com/ahoward/mongoid-grid_fs/blob/master/test/mongoid-grid_fs_test.rb#L201