MongoDB GridFS命令列工具mongofiles使用舉例
我們先看下mongofiles的幫助:
C:\Users\duansf>mongofiles --help
Browse and modify a GridFS filesystem.
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 begin with.
search - search all files. 'gridfs filename' is a substring
which listed filenames must contain.
put - add a file with filename 'gridfs filename'
get - get a file with filename 'gridfs filename'
delete - delete all files with filename 'gridfs filename'
Options:
--help produce help message
-v [ --verbose ] be more verbose (include multiple times
for more verbosity e.g. -vvvvv)
--quiet silence all non error diagnostic
messages
--version print the program'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 IPv6 support (disabled by
default)
-u [ --username ] arg username
-p [ --password ] arg password
--authenticationDatabase arg user source (defaults to dbname)
--authenticationMechanism arg (=MONGODB-CR)
authentication mechanism
--gssapiServiceName arg (=mongodb) Service name to use when authenticating
using GSSAPI/Kerberos
--gssapiHostName arg Remote host name to use for purpose of
GSSAPI/Kerberos authentication
--dbpath arg directly access mongod database files
in the given path, instead of
connecting to a mongod server - needs
to lock the data directory, so cannot
be used if a mongod is currently
accessing the same path
--directoryperdb each db is in a separate directory
(relevant only if dbpath specified)
--journal enable journaling (relevant only if
dbpath specified)
-d [ --db ] arg database to use
-c [ --collection ] arg collection to use (some commands)
-l [ --local ] arg local filename for put|get (default is
to use the same name as 'gridfs
filename')
-t [ --type ] arg MIME type for put (default is to omit)
-r [ --replace ] Remove other files with same name after
PUT
舉例說明用法:
1).列出資料庫中的所有檔案:
C:\Users\duansf>mongofiles list
connected to: 127.0.0.1
2).新增檔案(需要指定路徑):
C:\Users\duansf>mongofiles put C:\duansf\README.txt
connected to: 127.0.0.1
added file: { _id: ObjectId('574acae594a9b76720e6768b'), filename: "C:\duansf\RE
ADME.txt", chunkSize: 261120, uploadDate: new Date(1464519397095), md5: "5827acc
dd624438fd1a4753dd652de2b", length: 251 }
done!
3).檢視資料庫中的檔案:
C:\Users\duansf>mongofiles list
connected to: 127.0.0.1
C:\duansf\README.txt 251 --代表檔案長度
檢視MongoDB中的資料:
C:\Users\duansf>mongo
MongoDB shell version: 2.6.6
connecting to: test
> db.fs.files.find() --預設情況下,files集合在fs名稱空間中建立
{ "_id" : ObjectId("574acae594a9b76720e6768b"), "filename" : "C:\\duansf\\README
.txt", "chunkSize" : 261120, "uploadDate" : ISODate("2016-05-29T10:56:37.095Z"),
"md5" : "5827accdd624438fd1a4753dd652de2b", "length" : 251 }
> exit
bye
4).支援搜尋命令:
C:\Users\duansf>mongofiles search README.txt
connected to: 127.0.0.1
C:\duansf\README.txt 251
5).刪除:
C:\Users\duansf>mongofiles delete C:\duansf\README.txt
connected to: 127.0.0.1
done!
再次檢視資料庫中的檔案,發現已刪除:
C:\Users\duansf>mongofiles list
connected to: 127.0.0.1
C:\Users\duansf>mongo
MongoDB shell version: 2.6.6
connecting to: test
> db.fs.files.find()
>
當然也可以上傳avi檔案:
C:\Users\duansf>mongofiles put C:\Users\duansf\Desktop\mongo.avi
connected to: 127.0.0.1
added file: { _id: ObjectId('574bb4b1a33eea4b12f0127a'), filename: "C:\Users\dua
nsf\Desktop\mongo.avi", chunkSize: 261120, uploadDate: new Date(1464579257427),
md5: "fb1ddd09355a9764d9f87700bc48dc70", length: 40161178 }
done!
C:\Users\duansf>mongo
> db.fs.files.find().pretty()
{
"_id" : ObjectId("574bb4b1a33eea4b12f0127a"),
"filename" : "C:\\Users\\duansf\\Desktop\\mongo.avi",
"chunkSize" : 261120,
"uploadDate" : ISODate("2016-05-30T03:34:17.427Z"),
"md5" : "fb1ddd09355a9764d9f87700bc48dc70",
"length" : 40161178
}
>
C:\Users\duansf>mongofiles list
connected to: 127.0.0.1
C:\Users\duansf\Desktop\mongo.avi 40161178
</set
C:\Users\duansf>mongofiles --help
Browse and modify a GridFS filesystem.
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 begin with.
search - search all files. 'gridfs filename' is a substring
which listed filenames must contain.
put - add a file with filename 'gridfs filename'
get - get a file with filename 'gridfs filename'
delete - delete all files with filename 'gridfs filename'
Options:
--help produce help message
-v [ --verbose ] be more verbose (include multiple times
for more verbosity e.g. -vvvvv)
--quiet silence all non error diagnostic
messages
--version print the program'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 IPv6 support (disabled by
default)
-u [ --username ] arg username
-p [ --password ] arg password
--authenticationDatabase arg user source (defaults to dbname)
--authenticationMechanism arg (=MONGODB-CR)
authentication mechanism
--gssapiServiceName arg (=mongodb) Service name to use when authenticating
using GSSAPI/Kerberos
--gssapiHostName arg Remote host name to use for purpose of
GSSAPI/Kerberos authentication
--dbpath arg directly access mongod database files
in the given path, instead of
connecting to a mongod server - needs
to lock the data directory, so cannot
be used if a mongod is currently
accessing the same path
--directoryperdb each db is in a separate directory
(relevant only if dbpath specified)
--journal enable journaling (relevant only if
dbpath specified)
-d [ --db ] arg database to use
-c [ --collection ] arg collection to use (some commands)
-l [ --local ] arg local filename for put|get (default is
to use the same name as 'gridfs
filename')
-t [ --type ] arg MIME type for put (default is to omit)
-r [ --replace ] Remove other files with same name after
PUT
舉例說明用法:
1).列出資料庫中的所有檔案:
C:\Users\duansf>mongofiles list
connected to: 127.0.0.1
2).新增檔案(需要指定路徑):
C:\Users\duansf>mongofiles put C:\duansf\README.txt
connected to: 127.0.0.1
added file: { _id: ObjectId('574acae594a9b76720e6768b'), filename: "C:\duansf\RE
ADME.txt", chunkSize: 261120, uploadDate: new Date(1464519397095), md5: "5827acc
dd624438fd1a4753dd652de2b", length: 251 }
done!
3).檢視資料庫中的檔案:
C:\Users\duansf>mongofiles list
connected to: 127.0.0.1
C:\duansf\README.txt 251 --代表檔案長度
檢視MongoDB中的資料:
C:\Users\duansf>mongo
MongoDB shell version: 2.6.6
connecting to: test
> db.fs.files.find() --預設情況下,files集合在fs名稱空間中建立
{ "_id" : ObjectId("574acae594a9b76720e6768b"), "filename" : "C:\\duansf\\README
.txt", "chunkSize" : 261120, "uploadDate" : ISODate("2016-05-29T10:56:37.095Z"),
"md5" : "5827accdd624438fd1a4753dd652de2b", "length" : 251 }
> exit
bye
4).支援搜尋命令:
C:\Users\duansf>mongofiles search README.txt
connected to: 127.0.0.1
C:\duansf\README.txt 251
5).刪除:
C:\Users\duansf>mongofiles delete C:\duansf\README.txt
connected to: 127.0.0.1
done!
再次檢視資料庫中的檔案,發現已刪除:
C:\Users\duansf>mongofiles list
connected to: 127.0.0.1
C:\Users\duansf>mongo
MongoDB shell version: 2.6.6
connecting to: test
> db.fs.files.find()
>
當然也可以上傳avi檔案:
C:\Users\duansf>mongofiles put C:\Users\duansf\Desktop\mongo.avi
connected to: 127.0.0.1
added file: { _id: ObjectId('574bb4b1a33eea4b12f0127a'), filename: "C:\Users\dua
nsf\Desktop\mongo.avi", chunkSize: 261120, uploadDate: new Date(1464579257427),
md5: "fb1ddd09355a9764d9f87700bc48dc70", length: 40161178 }
done!
C:\Users\duansf>mongo
> db.fs.files.find().pretty()
{
"_id" : ObjectId("574bb4b1a33eea4b12f0127a"),
"filename" : "C:\\Users\\duansf\\Desktop\\mongo.avi",
"chunkSize" : 261120,
"uploadDate" : ISODate("2016-05-30T03:34:17.427Z"),
"md5" : "fb1ddd09355a9764d9f87700bc48dc70",
"length" : 40161178
}
>
C:\Users\duansf>mongofiles list
connected to: 127.0.0.1
C:\Users\duansf\Desktop\mongo.avi 40161178
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15498/viewspace-2108870/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 快速掌握mongoDB(五)——通過mongofiles和C#驅動操作GridFSMongoDBC#
- 技術乾貨| 如何在MongoDB中輕鬆使用GridFS?MongoDB
- 列舉資料庫快取使用場景例項和命令速查表資料庫快取
- 列舉工具類
- MongoDB Sharding Balancer介紹和設定方法舉例MongoDB
- mongodb使用自帶命令工具匯出匯入資料MongoDB
- 使用node.js構建命令列工具Node.js命令列
- ROS命令列工具ROS命令列
- 列舉的幾種使用案例(簡單,進階,switch,單例)單例
- Java 利用列舉實現單例模式Java單例模式
- 【java】【列舉使用技巧】Java
- 使用列舉來寫出更優雅的單例設計模式單例設計模式
- Click: 命令列工具神器命令列
- EFCore之命令列工具命令列
- Java Stream六個使用舉例Java
- 舉例說明如何使用WebSQL?WebSQL
- torch.argmin()的使用舉例
- 用 nodejs 寫一個命令列工具 :建立 react 元件的命令列工具NodeJS命令列React元件
- 使用 MapStruct 對映列舉Struct
- 使用 CliWrap 讓C#中的命令列互動舉重若輕C#命令列
- 如何使用命令列工具檢查資料庫?命令列資料庫
- Effective Java - 構造器私有、列舉和單例Java單例
- 舉例說明陣列的排序方法有哪些?陣列排序
- JDK常用的命令列工具JDK命令列
- awk命令使用例項
- restorecon 命令使用例項REST
- Tee命令使用例項
- Python全棧MongoDB資料庫(聚合、二進位制、GridFS、pymongo模組)Python全棧MongoDB資料庫
- Git 命令列使用Git命令列
- 為什麼我牆裂建議大家使用列舉來實現單例。單例
- Java雙屬性列舉使用Java
- Dutree – Linux上的命令列磁碟使用情況分析工具Linux命令列
- pt-query-digest命令幫助彙總和舉例
- Java 列舉、JPA 和 PostgreSQL 列舉JavaSQL
- Vue-cli 命令列工具分析Vue命令列
- node.js 命令列工具(cli)Node.js命令列
- 俚語搜尋命令列工具命令列
- web3j命令列工具Web命令列
- modelscope 命令列工具下載模型命令列模型