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
8
votes
2 answers

Render Image Stored in Mongo (GridFS) with Node + Jade + Express

I have a small .png file stored in Mongo using GridFS. I would like to display the image in my web browser using Node + Express + Jade. I can retrieve the image fine e.g.: FileRepository.prototype.getFile = function(callback,id) { this.gs = new…
Click Ahead
  • 2,782
  • 6
  • 35
  • 60
8
votes
1 answer

Nodejs - HTTP Range support / Partial file download

I am creating a music web app that streams MP3s that I have stored in MongoDB(GridFS). My Question: How can I add http range support so that I can start streaming the audio file 1/2 of the way through without having to wait for the buffer. I know…
Quinton Pike
  • 3,823
  • 8
  • 31
  • 37
8
votes
1 answer

ActiveStorage without ActiveRecord rails 6

Is it possible to add ActiveStorage on rails 6 without adding ActiveRecord I am using API application having only mongoDB database. Now, as I have observed that FSGrid which actually a good option, having a database size issue and we want physical…
8
votes
1 answer

NestJS - Mongoose @InjectConnection unit testing

I have a service that uses the @InjectConnection decorator in it's constructor. I am unable to instantiate a testingModule for this service. The following error is thrown: Nest can't resolve dependencies of the AttachmentsService (?, winston).…
pantera
  • 163
  • 1
  • 10
8
votes
2 answers

Object storage for a web application

I am currently working on a website where, roughly 40 million documents and images should be served to it's users. I need suggestions on which method is the most suitable for storing content with subject to these requirements. System should be…
8
votes
1 answer

mongodb connection timeout error with mongoose and nodejs

I desperately need some help.I am trying to upload large file(8 GB) to gridfs using mongoose and nodeJS. But as the file is very large it takes some time to upload. And after a while I get the following…
jony70
  • 225
  • 1
  • 2
  • 12
8
votes
1 answer

How to overwrite image in mongoDB gridfs?

I am using MongoDB 3.2 and Java 1.8 version and mongo-java driver. I have saved images in database. I am able to save image, read image and read all images. Now I want to update image in GridFS. I want to overwrite image if name of image is same.…
Vishwas
  • 6,967
  • 5
  • 42
  • 69
8
votes
1 answer

Storing image in DB vs filesystem for user uploaded images in website

I am building a website where users will be allowed to upload images . There is also restriction on maximum amount of space each user can use . I have two ideas in mind . To store image in a NoSQL db like mongoDB using GridFS . To store the image…
Ahmed Shabib
  • 687
  • 1
  • 8
  • 16
7
votes
1 answer

How do I overwrite a file in MongoDB Gridfs?

I am writing to the MongoDB gridfs using the following code: MongoDB.Driver.GridFS.MongoGridFSCreateOptions createOptions = new MongoDB.Driver.GridFS.MongoGridFSCreateOptions(); createOptions.ContentType =…
Journeyman
  • 10,011
  • 16
  • 81
  • 129
7
votes
5 answers

Spring multipart file upload with gridfs size limit exception

Using Jhipster with Spring+Mongo and Gridfs to handle files saved in db. When I'm trying to upload files larger than 1Mb it gives me an 500 error: java.io.IOException: UT000054: The maximum size 1048576 for an individual file in a multipart request…
neptune
  • 1,211
  • 2
  • 19
  • 32
7
votes
2 answers

Mongo convert Document to DBObject

Hi I need to convert Mongo Document to DBObject (BasicDBObject). I am uploading a file to mongo using GridFS and I want to set metadata, which I get in document. I know Document is pretty much the same as DBObject. I know I can do something like…
6
votes
4 answers

HDFS vs GridFS: When to use which?

HDFS and GridFS are two great technologies for distributed file saving but what are their differences? What type of problems fit better to each?
iCode
  • 4,308
  • 10
  • 44
  • 77
6
votes
1 answer

What's the best way to store references to a gridFS file in a document?

I'm using MongoDB to store user profiles, and now I want to use GridFS to store a picture for each profile. The two ways I'm comparing linking the two documents are: A) Store a reference to the file ID in the user's image field: User: { "_id":…
Matt Stauffer
  • 2,706
  • 15
  • 20
6
votes
3 answers

"TypeError: GridFsStorage is not a constructor"

for some reason I keep getting a "TypeError: GridFsStorage is not a constructor" error. I have no idea why its giving me this error since I'm just following the official documentation. Storage and upload conn.once('open', ()=> { gfs =…
6
votes
1 answer

How to create mongoose model for GridFS collection?

So I am trying to create a mongoose model for GridFS collection but to no success. let bucket; (async () => { try { await mongoose.connect(process.env.MONGODB_URI, { useNewUrlParser: true }); const { db } = mongoose.connection; …
Anonymous
  • 363
  • 3
  • 13
1 2
3
73 74