mod_gridfs v0.3

Well, it was long time since my last post, but at least now I have something to tell about. mod_gridfs, an Apache 2.2+ module that serves files from MongoDB GridFS is now v0.3, supporting authentication, custom prefixes, read preference (currently only mode string is supported, tags will be added later), improved memory footprint and error logging.

UPDATE: Custom collection names are also supported now.


  1. This comment has been removed by the author.

  2. Thanks, this is awesome. Seems to be up and connecting to mongo, but i'm not sure hoe to configure it, any chance of some apache conf examples of routing requests to mod_gridfs?

    1. At a minimum (if you don't use authentication, replica sets, etc.) you only need to configure two parameters: GridFSConnection and GridFSDatabase. You configure them right in your virtual host or location definition.
      For example, if your database host is running on the same server (localhost) and database name is "test", you can use the following config:

      <VirtualHost *:80>
      ServerName www.example.org
      DocumentRoot /home/www.example.org/www

      GridFSConnection localhost
      GridFSDatabase test

      This will serve files from fs.files/fs.chunks collections in the "test" database on localhost.

  3. Hi Aristarkh, I'm having problems using mod_gridfs. I compiled and installed it using the Mercurial repo instructions and using just the GridFSConnection and GridFSDatabase parameters. However, I get errors trying to access the files I have stored in MongoDB.

    Let's say I have a file that is accessible from MongoDB with the following URL: http://my_mongodb_host:28017/my_collection/fs/files/my_image.jpg

    I configured mod_gridfs like this:

    GridFSConnection my_mongodb_host
    GridFSDatabase my_collection

    What would be the corresponding URL when accessing it from the Apache Server?

    1. Hi, Tiago!

      I guess you meant http://my_mongodb_host:28017/my_collection/fs/files/?filter_filename=my_image.jpg ?

      Your configuration should be sufficient. What do the Apache error logs say? Are there any gridfs-related messages, or maybe problems with module not being loaded for some reason?

    2. Thanks for the quick reply. Yes, the URL was wrong. What I want to know is, what should be the publicly visible URL for a file served by GridFS?

      Currently I get a huge amount of repeated errors in Apache's error looking for any URL I specify:

      [Mon Nov 25 13:26:21.107741 2013] [gridfs:warn] [pid 18548:tid 140614802208512] [client] mod_gridfs: Retrying after MongoDB exception for file 'my_image.jpg' (code: 11002, database: 'my_collection'): socket exception [CONNECT_ERROR] for my_mongodb_host

      Configuring GridFS also seems to lead to my /static and /media aliases being overriden and resulting in queries to MongoDB. My mod_wsgi application server configuration is also ignored.

      I'm not very proficient with Apache configuration, so there's probably a few obvious rookie mistakes that I'm making. Nevertheless, it's not obvious to me how to configure GridFS correctly, how to access files correctly and how to co-exist with other Apache URLs.

    3. This error means that mod_gridfs can't connect to the database. Are the host and port correct? Can you connect to the database from the machine that runs Apache with something like "telnet my_mongodb_host 27017"?

      As for having mod_gridfs running only for specific URL prefixes, please use Apache location-based configuration (some good official docs here), please check a short discussion we had with another mod_gridfs user on this topic that contains an example of configuration file that allows to serve files from GridFS only for a subset of paths.