Post List

2015년 8월 12일 수요일

MongoDB Study #17 GridFS

1. Grid File System

대용량 File을 Database에 Upload / Download 할 수 있는 기능을 제공합니다. (최대 16MB)
파일은 255KB의 Chunk 단위로 분리되어 Document로 저장됩니다.

실습을 위해서 http://www.pitmongo.co.kr 의 기술자료 폴더로 가셔서
BIG_EMP.TXT 파일을 다운로드 받으신 후 MongoDB 가 설치된 bin 폴더로 복사하세요.

C:\MongoDB\bin>mongofiles list
2015-08-12T09:17:16.859+0900    connected to: localhost
C:\MongoDB\bin>mongofiles put BIG_EMP.TXT         // Upload
2015-08-12T09:17:34.646+0900    connected to: localhost
added file: BIG_EMP.TXT
C:\MongoDB\bin>mongofiles list
2015-08-12T09:18:47.560+0900    connected to: localhost
BIG_EMP.TXT     2892607
C:\MongoDB\bin>mongo
> show collections
...
fs.chunks
fs.files
...
> show dbs
admin  0.078GB
local  0.078GB
test   0.203GB
> db.fs.files.find().pretty()
{
        "_id" : ObjectId("55ca909ef867d6336c000001"),
        "chunkSize" : 261120,
        "uploadDate" : ISODate("2015-08-12T00:17:34.690Z"),
        "length" : 2892607,
        "md5" : "5847679427ed8528c2b0103d1923bff4",
        "filename" : "BIG_EMP.TXT"
}
> exit
bye
C:\MongoDB\bin>del BIG_EMP.TXT
C:\MongoDB\bin>mongofiles get BIG_EMP.TXT          // Download
2015-08-12T09:20:37.386+0900    connected to: localhost
finished writing to: BIG_EMP.TXT
C:\MongoDB\bin>dir
...
2015-08-12  오전 09:20         2,892,607 BIG_EMP.TXT
...
C:\MongoDB\bin>mongofiles delete BIG_EMP.TXT
2015-08-12T09:36:45.153+0900    connected to: localhost
successfully deleted all instances of 'BIG_EMP.TXT' from GridFS

C:\MongoDB\bin>mongo
> db.fs.chunks.find()
> db.fs.files.validate()
{
        "ns" : "test.fs.files",
        "datasize" : 0,
        "nrecords" : 0,
        "lastExtentSize" : 8192,
        "firstExtent" : "0:201000 ns:test.fs.files",
        "lastExtent" : "0:201000 ns:test.fs.files",
        "extentCount" : 1,
        "firstExtentDetails" : {
                "loc" : "0:201000",
                "xnext" : "null",
                "xprev" : "null",
                "nsdiag" : "test.fs.files",
                "size" : 8192,
                "firstRecord" : "null",
                "lastRecord" : "null"
        },
        "deletedCount" : 2,
        "deletedSize" : 8016,
        "nIndexes" : 1,
        "keysPerIndex" : {
                "test.fs.files.$_id_" : 0
        },
        "valid" : true,
        "errors" : [ ],
        "warning" : "Some checks omitted for speed. use {full:true} option to do more thorough scan.",
        "ok" : 1
}

댓글 없음:

댓글 쓰기