時間:2024-03-08 08:50作者:下載吧人氣:15
概述
mongoexport命令行用于數據的導出,默認導出的文件格式為JSON格式。當然也可以指定特定的文件格式。
語法
C:mongobin>mongoexport -help
options:
–help produce help message
-v [ –verbose ] be more verbose (include multiple times for more
verbosity e.g. -vvvvv)
-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
–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 if dbpath specified, each db is in a separate
directory
-d [ –db ] arg database to use
-c [ –collection ] arg collection to use (some commands)
-f [ –fields ] arg comma separated list of field names e.g. -f name,age
–fieldFile arg file with fields names – 1 per line
-q [ –query ] arg query filter, as a JSON string
–csv export to csv instead of json
-o [ –out ] arg output file; if not specified, stdout is used
–jsonArray output to a json array rather than one object per
Line
說明:
引言
今天在用mongoexport導出滿足一定條件下的數據時,遇到了一個報錯,現紀錄下來,并且針對此錯誤對MongoDB 的 數字類型做了進一步的學習。
背景 及 報錯信息
今天接到一個業務需求,需要從MongoDB 數據庫 order集合中導出符合以下條件的數據:
db.qqwj_order.find({“Source”:NumberInt(“21″),”Batch”:”支付中的訂單提醒:2018/9/5″,”MsgContent”:/還未完成在線付款/})
通過MongoDB 客戶端工具 【NoSQLBooster for MongoDB】查詢檢查,語句執行正常,顯示相應記錄數為 15265。
導出數據使用mongoexport命令,執行命令如下:
/data/mongodb/mongobin344/bin/mongoexport -h 172.X.X.XXX –port 端口 –db 數據庫 -u 賬號 -p ‘密碼’ –authenticationDatabase 認證數據庫 –type=csv -c qqwj_order -f MsgContent,REC_CreateTime -q ‘{ “Source”:NumberInt(“21″),”Batch”:”支付中的訂單提醒:2018/9/5″,”MsgContent”:/還未完成在線付款/}’ -o /data/mongodb_back/sms.csv
網友評論