database/noSql

GridFs

아르르르를를르 2019. 11. 10. 15:50

MongoDB의 Document의 최대 크기는 16MB이다. 그보다 큰 document는 GridFs를 사용해야 한다.

GridFs는 모든 파일을 Bson document 형식으로 처리하여 16MB가 넘은 데이터를 분산하여 저장하는 명세이다.

16MB가 넘지 않더라도 전체 파일을 메모리에 로드하지 않고도 저장하는데 유용하다.

파일 하나로 저장하는 것이 아니라 255KB 이하 크기의 chunk로 나누어 저장하는데,

fs.chunks, fs.files 2개의 collection을 통해 파일 청크와 메타데이터를 관리한다. 

 

fs.chunks

{
  "_id" : <ObjectId>,
  "files_id" : <ObjectId>,
  "n" : <num>,
  "data" : <binary>
}

 

 

fs.files

{
  "_id" : <ObjectId>,
  "length" : <num>,
  "chunkSize" : <num>,
  "uploadDate" : <timestamp>,
  "md5" : <hash>,    # Deprecated
  "filename" : <string>,
  "contentType" : <string>,    # Deprecated
  "aliases" : <string array>,    # Deprecated
  "metadata" : <any>,
}

files._id

The unique identifier for this document. The _id is of the data type you chose for the original document. The default type for MongoDB documents is BSON ObjectId.

 

files.length

The size of the document in bytes.

 

files.chunkSize

The size of each chunk in bytes. GridFS divides the document into chunks of size chunkSize, except for the last, which is only as large as needed. The default size is 255 kilobytes (kB).

 

files.uploadDate

The date the document was first stored by GridFS. This value has the Date type.

 

files.filename

Optional. A human-readable name for the GridFS file.

 

files.metadata

Optional. The metadata field may be of any data type and can hold any additional information you want to store. If you wish to add additional arbitrary fields to documents in the files collection, add them to an object in the metadata field.

'database > noSql' 카테고리의 다른 글

카산드라 아키텍쳐  (0) 2020.12.08
mongodb와 cassandra 비교  (0) 2020.11.30
server 상태 조회  (0) 2020.06.30
mongodb cluster 구축  (0) 2019.12.20