In ruby using the mongo gem I can’t find any documentation on how to find on a filename with GridFs.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
First get a connection to the database, we’ll call this
db. Then you can connect to your GridFS as a Mongo::Grid or Mongo::GridFileSystem instance:Now you can use the Mongo::GridExt::InstanceMethods methods on
fs. In particular, you can useexist?:The
exist?method is poorly named as it gives you a Hash if it finds something and anilif it doesn’t.That’s not terribly useful if you’re searching for, say, all filenames that match
/pancakes/. However, GridFS is just a pair of normal MongoDB collections:fs.files: the file metadata.fs.chunks: the file data (in chunks).If you want to do arbitrary metadata searches then you just need to get your hands on
fs.filesand have your way with it:The
fsabove will be a Mongo::Collection so itsfindmethod accepts all the usual query options.