# Giới thiệu GridFS

**GridFS** là MongoDB Specification để lưu giữ và thu thập các file lớn như các image, audio, video file, … Nó là một loại của hệ thống file để lưu giữ các file nhưng dữ liệu của nó được lưu giữ bên trong các Collection của MongoDB. GridFS có khả năng lưu giữ các file ngay cả khi kích cỡ của nó lớn hơn giới hạn kích cỡ là 16 MB của Document.

GridFS phân chia một file thành các Chunk và lưu giữ mỗi mảng dữ liệu trong một Document riêng, kích cỡ tối đa của nó là 255k.

Theo mặc định, GridFS sử dụng hai Collection là **fs.files** và **fs.chunks** để lưu giữ metadata của file và các chunk. Mỗi Chunk được nhận diện bởi trường **\_id** ObjectId duy nhất. **fs.files**hoạt động như là một Document cha. Trường **files\_id** trong fs.chunks liên kết Chunk tới Document cha của nó.

Dưới đây là Document mẫu của **fs.files** collection:

```javascript
{

    "filename": "test.txt",

    "chunkSize": NumberInt(261120),

    "uploadDate": ISODate("2014-04-13T11:32:33.557Z"),

    "md5": "7b762939321e146569b07f72c62cca4f",

    "length": NumberInt(646)

}
```

Document xác định tên file, kích cỡ chunk, ngày cập nhật, và độ dài.

Dưới đây là Document mẫu của fs.chunks document:

```
{

    "files_id": ObjectId("534a75d19f54bfec8a2fe44b"),

    "n": NumberInt(0),

    "data": "Mongo Binary Data"

}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://janeto.gitbook.io/mongodb-toan-tap/gridfs-trong-mongodb/gioi-thieu-gridfs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
