Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7633787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:59:02+00:00 2026-05-31T06:59:02+00:00

In ruby using the mongo gem I can’t find any documentation on how to

  • 0

In ruby using the mongo gem I can’t find any documentation on how to find on a filename with GridFs.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T06:59:03+00:00Added an answer on May 31, 2026 at 6:59 am

    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:

    fs = Mongo::Grid.new(db)
    fs = Mongo::GridFileSystem.new(db)
    

    Now you can use the Mongo::GridExt::InstanceMethods methods on fs. In particular, you can use exist?:

    f = fs.exist? :filename => 'pancakes.png'
    

    The exist? method is poorly named as it gives you a Hash if it finds something and a nil if 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.files and have your way with it:

    fs     = db['fs.files']
    cursor = fs.find(:filename => /pancakes/)
    # Now iterate through cursor or .count it or ...
    

    The fs above will be a Mongo::Collection so its find method accepts all the usual query options.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on creating a daemon in Ruby using the daemons gem. I
I am using mongo-ruby-driver, I want to get stats/query graphs to show for Mongo.
I want to upsert a document with the mongo-ruby-driver using something like the following-
I have a Rails 3.1 app, running on Ruby 1.9.2, Mongo 2.0.2, using Mongoid
Uing Ruby (1.8.7) and Mongo Driver, I've written this: @data['Users'] = [] @database['user_facilities'].find({ :facility_id
I started using NoSQL with Ruby. Here's the code I have require 'mongo' require
I'm retrieving results from mongo based on a geo query using the ruby driver.
How can I, very simply construct a hash in ruby using something simple like
ruby version is 1.9.2p290 I am using the following gemset D:\work\software\mongoid>gem list * LOCAL
I'm using Ubuntu Server 10, Ruby 1.9.2 When I try to require 'mongo' it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.