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之GridFSMongoDB
- Spring Data MongoDB支援GridFSSpringMongoDB
- MongoDB正規表示式匹配使用方法舉例MongoDB
- 使用SVN命令列工具命令列
- 列舉工具類
- 技術乾貨| 如何在MongoDB中輕鬆使用GridFS?MongoDB
- 列舉資料庫快取使用場景例項和命令速查表資料庫快取
- DNS列舉工具DNSenumDNS
- Java列舉使用Java
- sqlcipher 命令列使用及工具下載SQL命令列
- svn命令列工具安裝使用(windows)命令列Windows
- RID列舉工具RidEnumIDE
- SNMP OID批量列舉工具
- 【java】【列舉使用技巧】Java
- 使用node.js構建命令列工具Node.js命令列
- ROS命令列工具ROS命令列
- mongodb使用自帶命令工具匯出匯入資料MongoDB
- 列舉的幾種使用案例(簡單,進階,switch,單例)單例
- Java 利用列舉實現單例模式Java單例模式
- 透過列舉enum實現單例單例
- MongoDB Sharding Balancer介紹和設定方法舉例MongoDB
- java中列舉(Enum)使用Java
- JAVA列舉使用詳解Java
- TortoiseSVN 命令 (命令列執行工具)命令列
- 為什麼建議使用命令列工具?命令列
- 使用列舉來寫出更優雅的單例設計模式單例設計模式
- Click: 命令列工具神器命令列
- EFCore之命令列工具命令列
- windows命令列工具(轉)Windows命令列
- 列舉單例模式如何防止反射攻擊單例模式反射
- Java Stream六個使用舉例Java
- 4 個 lvcreate 常用命令舉例
- 使用 CliWrap 讓C#中的命令列互動舉重若輕C#命令列
- Java雙屬性列舉使用Java
- 使用 MapStruct 對映列舉Struct
- Windows下SVN命令列工具使用詳解(附加TortoiseSVN)Windows命令列
- 如何使用命令列工具檢查資料庫?命令列資料庫