Questions tagged [gridfs]

GridFS is a specification for storing large files in MongoDB. All of the mongodb.com supported drivers implement the GridFS spec.

GridFS is a specification for storing large files in MongoDB. MongoDB supports storing binary data directly within BSON documents, however the size is limited by the database's maximum document size (16MB as of the 1.8 production version of MongoDB; 4MB in older versions).

GridFS works by splitting large files into small "chunks", usually 256k in size.

GridFS uses two collections to store data:

  • chunks contains the binary segments of files
  • files contains metadata including the filename, content type, md5 checksum, and any optional information added by the developer

Each file saved in GridFS will have one document in the files collection and one or more documents in the chunks collection.

The GridFS collections also use a prefix (aka namespace). The default prefix is fs, so the default collection names are fs.chunks and fs.files.

GridFS collections are stored in normal MongoDB databases, and can be scaled with standard features such as replication and sharding.

Working with GridFS

All of the mongodb.org supported drivers implement the GridFS spec.

The command-line utility mongofiles can also be used to save, retrieve, list, search, and remove files in GridFS.

Related Links

1101 questions
15
votes
1 answer

Storing very large documents in MongoDB

In short: If you have a large number of documents with varying sizes, where relatively few documents hit the maximum object size, what are the best practices to store those documents in MongoDB? I have set of documents like: {_id: ..., values:…
Ruggiero Spearman
  • 6,735
  • 5
  • 26
  • 37
14
votes
3 answers

MongoDB remove GridFS objects from shell

I have files stored in a MongoDB using GridFS. I need to remove some of those files by ID, from the JavaScript shell. I need to remove a single file using it's ID. I figured I could just do this: db.fs.files.remove({_id: my_id}); This works to some…
Alex Turpin
  • 46,743
  • 23
  • 113
  • 145
14
votes
3 answers

Should I use GridFS or binary data to store & retrieve images from MongoDB?

I was wondering which is better/faster: Having a separate collection of documents that just contain the image saved as binary data, and possibly some metadata. Or using GridFS to store the images.
mcls
  • 9,071
  • 2
  • 29
  • 28
13
votes
1 answer

Can you stream video from GridFS (MongoDB filesystem)?

Can you tell a streaming server such as Ngix to stream videos stored in GridFS? If yes, does it affect perfs?
Bite code
  • 578,959
  • 113
  • 301
  • 329
12
votes
3 answers

how to replace gridStore to gridFSBucket?

I have this error message: (node:11976) DeprecationWarning: GridStore is deprecated, and will be removed in a future version. Please use GridFSBucket instead and sometimes I have trouble viewing the picture , I guess because of that, due to poor…
Alexander
  • 1,288
  • 5
  • 19
  • 38
11
votes
4 answers

Querying MongoDB GridFS?

I have a blogging system that stores uploaded files into the GridFS system. Problem is, I dont understand how to query it! I am using Mongoose with NodeJS which doesnt yet support GridFS so I am using the actual mongodb module for the GridFS…
Quinton Pike
  • 3,823
  • 8
  • 31
  • 37
11
votes
2 answers

Convert Base64 image to raw binary with Node.js

I have found posts that are close to what I'm looking for, but I have not been able to successfully implement what I want. Here is the general flow: Submit photo with rest of venue data, as base64 data Strip data prefix if it exists, so I have just…
remotevision
  • 433
  • 1
  • 6
  • 14
10
votes
1 answer

How can I backup a MongoDB GridFS database the easiest way?

Like the title says, I have a MongoDB GridFS database with a whole range of file types (e.g., text, pdf, xls), and I want to backup this database the easiest way. Replication is not an option. Preferably I'd like to do it the usual database way of…
c00kiemonster
  • 22,241
  • 34
  • 95
  • 133
10
votes
2 answers

MongoDB as static files provider?

It's MongoDB a good candidate to serve static files (files, video) as cdn. I searching a solid way to store big amounts of data (>+To) remplacing S3 and managing cache features. Experiences. Thanks.
user325558
  • 1,413
  • 5
  • 22
  • 35
10
votes
2 answers

pymongo not able to retrieve files

I am playing around with mongodb (GridFS) to store files (zip) and try to retrieve them using python`s "pymongo" but its not working as expected i am not able to understand how to retrieve the file(s) i have addedd ... Below is the code i ran from…
Ninad Mhatre
  • 549
  • 1
  • 7
  • 17
10
votes
2 answers

Saving a file in Mongodb's GridFS with pymongo results in a truncated file - python 2.7 on Windows 7

Saving a file in Mongodb's GridFS with pymongo results in a truncated file. from pymongo import MongoClient import gridfs import os #just to make sure we aren't crazy, check the filesize on disk: print os.path.getsize( r'owl.jpg' ) #add the file…
D. Reagan
  • 841
  • 1
  • 8
  • 24
10
votes
3 answers

Query on MongoDB GridFS metadata (Java)

What I'm trying to do is fetching a list of GridFS files by querying an field of the metadata. For example I got a GridFS file document looking like: { "_id" : { "$oid" : "4f95475f5ef4fb269dbac954"} , "chunkSize" : 262144 , "length" : 3077 , "md5" :…
sebastian
  • 2,427
  • 4
  • 32
  • 37
9
votes
2 answers

Is GridFS faster than usual FS?

I wonder whether storing all the uploaded files in GridFS is faster than storing them on the usual filesystem, e.g. Ext4 (in terms of reading/writing speed and average server load).
eigenein
  • 2,083
  • 3
  • 25
  • 43
9
votes
1 answer

Store file in Mongo's GridFS with ExpressJS after upload

I have started building a REST api using expressJS. I am new to node so please bear with me. I want to be able to let users upload a file directly to Mongo's GridFS using a post to the /upload route. From what I understand in expressJS documentation…
Maarten
  • 635
  • 2
  • 8
  • 22
9
votes
3 answers

Mongodb base64 image vs gridfs

I'm using mongodb and I want to store some thumbnails in my server. What's best? Using GridFS or converting those images to base64 and store them directly inside a document.
danielrvt
  • 10,177
  • 20
  • 80
  • 121
1
2
3
73 74