本文共 2307 字,大约阅读时间需要 7 分钟。
Export data from MongoDB in CSV or JSON format.
See http://docs.mongodb.org/manual/reference/program/mongoexport/ for more information.
general options:
--help print usage
--version print the tool version and
exit
verbosity options:
-v, --verbose=<level> more detailed log output
(include multiple times for
more verbosity, e.g. -vvvvv,
or specify a numeric value,
e.g. --verbose=N)
--quiet hide all log output
connection options:
-h, --host=<hostname> mongodb host to connect to
(setname/host1,host2 for
replica sets)
--port=<port> server port (can also use
--host hostname:port)
authentication options:
-u, --username=<username> username for authentication
-p, --password=<password> password for authentication
--authenticationDatabase=<database-name> database that holds the
user's credentials
--authenticationMechanism=<mechanism> authentication mechanism to
use
namespace options:
-d, --db=<database-name> database to use
-c, --collection=<collection-name> collection to use
output options:
-f, --fields=<field>[,<field>]* comma separated list of field
names (required for exporting
CSV) e.g. -f "name,age"
--fieldFile=<filename> file with field names - 1 per
line
--type=<type> the output format, either
json or csv (defaults to
'json')
-o, --out=<filename> output file; if not
specified, stdout is used
--jsonArray output to a JSON array rather
than one object per line
--pretty output JSON formatted to be
human-readable
querying options:
-q, --query=<json> query filter, as a JSON
string, e.g., '{x:{$gt:1}}'
--queryFile=<filename> path to a file containing a
query filter (JSON)
-k, --slaveOk allow secondary reads if
available (default true)
--readPreference=<string>|<json> specify either a preference
name or a preference json
object
--forceTableScan force a table scan (do not
use $snapshot)
--skip=<count> number of documents to skip
--limit=<count> limit the number of documents
to export
--sort=<json> sort order, as a JSON string,
e.g. '{x:1}'
mongoexport -h 127.0.0.1:27017 -u hello -p world -d mydb -c audits -q '{actionCode:"701"}' --sort '{createDate:1}' --type=csv -f actionCode,actionName,user,createDate,createDateStr,domain -o login.csv
-h 数据地址:端口
-u 数据库用户名称
-p 数据库用户密码
-c 数据库集合名称(表名称)
-q查询条件
--sort 对查询结果按照某个字段进行排序
--type=csv 指定查询结果输出格式,csv或者json
-f 指定查询结果要输出的字段
-o 输出文件名称
转载地址:http://wxrji.baihongyu.com/