mongo命令行常见操作
mongo
连接
./mongo
查看数据库
> show databases;
admin 0.000GB
config 0.000GB
gridFS 0.000GB
local 0.000GB
mongofiles
帮助
./mongofiles --help
Usage:
mongofiles <options> <command> <filename or _id>
Manipulate gridfs files using the command line.
Possible commands include:
list - list all files; 'filename' is an optional prefix which listed filenames must begin with
search - search all files; 'filename' is a substring which listed filenames must contain
put - add a file with filename 'filename'
put_id - add a file with filename 'filename' and a given '_id'
get - get a file with filename 'filename'
get_id - get a file with the given '_id'
delete - delete all files with filename 'filename'
delete_id - delete a file with the given '_id'
上传文件
将本地 hello.txt
上传,保存成文件 hello.txt
# ./mongofiles put hello.txt
2020-02-07T14:59:31.536+0800 connected to: localhost
added file: hello.txt
将本地文件 abc.txt
上传,保存到数据库 mytest
中的文件 nabc.txt
# ./mongofiles -d mytest -l abc.txt put "nabc.txt"
2020-02-07T15:27:52.904+0800 connected to: localhost
added file: nabc.txt
查看文件
# ./mongofiles list
2020-02-07T14:59:59.712+0800 connected to: localhost
hello.txt 22
搜索文件
./mongofiles search x
2020-02-07T15:00:15.743+0800 connected to: localhost
hello.txt 22
下载文件
下载默认数据库中的 hello.txt
,保存成本地文件 hello.txt
# ./mongofiles get hello.txt
2020-02-07T15:02:05.850+0800 connected to: localhost
finished writing to hello.txt
下载数据库 mytest
中的 nabc.txt
文件,保存成本地文件 mabc.txt
# ./mongofiles get "nabc.txt" -d mytest -l "mabc.txt"
2020-02-07T15:41:51.203+0800 connected to: localhost
finished writing to mabc.txt
删除文件
删除默认数据库中的 hello.txt
文件
# ./mongofiles delete hello.txt
2020-02-07T15:43:21.649+0800 connected to: localhost
successfully deleted all instances of 'hello.txt' from GridFS
删除数据库 mytest
中所有的 nabc.txt
# ./mongofiles -d mytest delete nabc.txt
2020-02-07T15:43:54.031+0800 connected to: localhost
successfully deleted all instances of 'nabc.txt' from GridFS
图形界面工具
MongoChef
略