Closed abhas closed 10 years ago
@abhas, Is this still a problem? If so, would you mind putting together a failing test case that exposes the problem?
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.
@abhas Any time to follow-up on this?
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"
@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.
@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>
@abhas there is an example in the tests -> https://github.com/ahoward/mongoid-grid_fs/blob/master/test/mongoid-grid_fs_test.rb#L201
I tried creating a custom namespace as follows:
So
f
returns aGridFS::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
andimage.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?