27.4k views
5 votes
How does MongoDB store a large document such as a photo or video file which is over 200MB?

A) use GridFS
B) use replication
C) use sharding
D) cannot be stored because the file is over 16 MB limit

1 Answer

3 votes

Final answer:

MongoDB uses GridFS to store large documents such as photo or video files that are over 200MB by automatically splitting the file into smaller chunks and storing them as separate documents in a grid file system collection.

Step-by-step explanation:

MongoDB uses GridFS to store large documents such as photo or video files that are over 200MB. GridFS is a specification that allows MongoDB to store and retrieve files that exceed the BSON document size limit of 16MB. It automatically splits the large file into smaller chunks and stores them as separate documents in a grid file system collection in MongoDB.

When a file is stored using GridFS, it is divided into chunks, typically 255KB in size, and each chunk is stored as a separate document in the grid file system collection. Metadata about the file, such as its filename and content type, is stored in a separate document called the file document. This allows the application to retrieve and reconstruct the complete file from the chunks when needed.

Using GridFS, MongoDB ensures efficient storage and retrieval of large files while leveraging the features and scalability of the MongoDB database.

User Kretzm
by
7.0k points