時間:2024-03-08 08:50作者:下載吧人氣:18
概述
mongoexport命令行用于數(shù)據(jù)的導(dǎo)出,默認(rèn)導(dǎo)出的文件格式為JSON格式。當(dāng)然也可以指定特定的文件格式。
語法
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導(dǎo)出滿足一定條件下的數(shù)據(jù)時,遇到了一個報錯,現(xiàn)紀(jì)錄下來,并且針對此錯誤對MongoDB 的 數(shù)字類型做了進一步的學(xué)習(xí)。
背景 及 報錯信息
今天接到一個業(yè)務(wù)需求,需要從MongoDB 數(shù)據(jù)庫 order集合中導(dǎo)出符合以下條件的數(shù)據(jù):
db.qqwj_order.find({“Source”:NumberInt(“21″),”Batch”:”支付中的訂單提醒:2018/9/5″,”MsgContent”:/還未完成在線付款/})
通過MongoDB 客戶端工具 【NoSQLBooster for MongoDB】查詢檢查,語句執(zhí)行正常,顯示相應(yīng)記錄數(shù)為 15265。
導(dǎo)出數(shù)據(jù)使用mongoexport命令,執(zhí)行命令如下:
/data/mongodb/mongobin344/bin/mongoexport -h 172.X.X.XXX –port 端口 –db 數(shù)據(jù)庫 -u 賬號 -p ‘密碼’ –authenticationDatabase 認(rèn)證數(shù)據(jù)庫 –type=csv -c qqwj_order -f MsgContent,REC_CreateTime -q ‘{ “Source”:NumberInt(“21″),”Batch”:”支付中的訂單提醒:2018/9/5″,”MsgContent”:/還未完成在線付款/}’ -o /data/mongodb_back/sms.csv
網(wǎng)友評論