MongoDB 進階(GridFS)

來源:互聯網
上載者:User

GridFS是一種在MongoDB中儲存大二進位檔案的機制。使用GridFS存檔案有如下幾個原因:

● GridFS可以簡化需求。如果已經用了MongoDB,GridFS就可以不需要獨立的檔案儲存體架構。

● GridFS利用已經建立的複製和分區機制,所以對於檔案儲存體來說故障恢複和擴充都很容易。

● GridFS可以避免用於儲存使用者上傳內容的檔案系統出現的某些問題。例如:GridFS在同一目錄下放置大量檔案是沒有任何問題的。

● GridFS不產生磁片,因為MongoDB分配的資料檔案空間以2G為一塊。

  使用GridFS:mongofiles

mongofiles是GridFS的工具 + 生產力,用於管理GridFS檔案

 

--協助命令

[root@racdb ~]# mongofiles--help

Browse and modify a GridFSfilesystem.

 

usage: mongofiles [options]command [gridfs filename]

command:

  one of (list|search|put|get)

  list - list all files.  'gridfs filename' is an optional prefix

         which listed filenames must beginwith.

  search - search all files. 'gridfs filename'is a substring

           which listed filenames must contain.

  put - add a file with filename 'gridfsfilename'

  get - get a file with filename 'gridfsfilename'

  delete - delete all files with filename'gridfs filename'

options:

  --help                                produce helpmessage

  -v [ --verbose ]                      be more verbose (includemultiple times

                                        formore verbosity e.g. -vvvvv)

  --version                             print theprogram's version and exit

  -h [ --host ] arg                     mongo host to connect to (<set

                                       name>/s1,s2 for sets)

  --port arg                            server port. Can also use --host

                                       hostname:port

  --ipv6                                enable IPv6support (disabled by

                                       default)

  -u [ --username ] arg                 username

  -p [ --password ] arg                 password

  --authenticationDatabase arg          user source (defaults to dbname)

  --authenticationMechanism arg (=MONGODB-CR)

                                        authentication mechanism

  --dbpath arg                          directly accessmongod database files

                                        in thegiven path, instead of

                                       connecting to a mongod  server -needs

                                        to lockthe data directory, so cannot

                                        be usedif a mongod is currently

                                       accessing the same path

  --directoryperdb                      each db is in a separate directly

                                       (relevant only if dbpath specified)

  --journal                             enable journaling(relevant only if

                                        dbpathspecified)

  -d [ --db ] arg                       database to use

  -c [ --collection ] arg               collection to use (somecommands)

  -l [ --local ] arg                    local filename for put|get(default is

                                        to usethe same name as 'gridfs

                                       filename')

  -t [ --type ] arg                     MIME type for put (defaultis to omit)

  -r [ --replace ]                      Remove other files withsame name after

                                        PUT

                                       

--上傳檔案

[root@racdb ~]# mongofiles put foo.log

connected to: 127.0.0.1

added file: { _id:ObjectId('56caba480ad7ef0aa8a76f0c'), filename: "foo.log", chunkSize:261120, uploadDate: new Date(1456126536618), md5:"d1bfff5ab0cc6b652aaf08345b19b7e6", length: 21 }

done!

--列出檔案

[root@racdb ~]# mongofiles list

connected to: 127.0.0.1

install.log     54876

foo.log 21

--下載檔案

[root@racdb ~]# rm -f foo.log

[root@racdb ~]# mongofiles get foo.log

connected to: 127.0.0.1

done write to: foo.log

[root@racdb ~]# ll foo.log

-rw-r--r--. 1 root root 21 2月  22 15:36 foo.log

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.