12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
ADADADADAD
建站问答 时间:2024-12-01 18:58:09
作者:文/会员上传
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
mongodb导出脚本的方法:在mongodb中能够使用mongoexport工具将一个集合导出成JSON格式或CSV格式的文件,语法格式:“mongoexport -d 数据库 -c 集合名称 -o 文件路径”,该语句的
以下为本文的正文内容,内容仅供参考!本站为公益性网站,复制本文以及下载DOC文档全部免费。
mongodb导出脚本的方法:在mongodb中能够使用mongoexport工具将一个集合导出成JSON格式或CSV格式的文件,语法格式:“mongoexport -d 数据库 -c 集合名称 -o 文件路径”,该语句的参数说明:-d指明数据库的名字、-c指明collection的名字、-o:指明到要导出的文件名。
具体内容如下:
Mongodb中的mongoexport工具可以把一个collection导出成JSON格式或CSV格式的文件。可以通过参数指定导出的数据项,也可以根据指定的条件导出数据。mongoexport具体用法如下所示:
[root@lb-vm5bin]#./mongoexport--helpUsage:mongoexport<options>
ExportdatafromMongoDBinCSVorJSONformat.
Seehttp://docs.mongodb.org/manual/reference/program/mongoexport/formoreinformation.
generaloptions:
--helpprintusage
--versionprintthetoolversionandexit
verbosityoptions:
-v,--verbose=<level>moredetailedlogoutput(includemultipletimesformoreverbosity,e.g.-vvvvv,orspecifyanumericvalue,e.g.--verbose=N)
--quiethidealllogoutput
connectionoptions:
-h,--host=<hostname>mongodbhosttoconnectto(setname/host1,host2forreplicasets)
--port=<port>serverport(canalsouse--hosthostname:port)
ssloptions:
--sslconnecttoamongodormongosthathassslenabled
--sslCAFile=<filename>the.pemfilecontainingtherootcertificatechainfromthecertificateauthority
--sslPEMKeyFile=<filename>the.pemfilecontainingthecertificateandkey
--sslPEMKeyPassword=<password>thepasswordtodecryptthesslPEMKeyFile,ifnecessary
--sslCRLFile=<filename>the.pemfilecontainingthecertificaterevocationlist
--sslAllowInvalidCertificatesbypassthevalidationforservercertificates
--sslAllowInvalidHostnamesbypassthevalidationforservername
--sslFIPSModeuseFIPSmodeoftheinstalledopenssllibrary
authenticationoptions:
-u,--username=<username>usernameforauthentication
-p,--password=<password>passwordforauthentication
--authenticationDatabase=<database-name>databasethatholdstheuser'scredentials
--authenticationMechanism=<mechanism>authenticationmechanismtouse
namespaceoptions:
-d,--db=<database-name>databasetouse
-c,--collection=<collection-name>collectiontouse
outputoptions:
-f,--fields=<field>[,<field>]*commaseparatedlistoffieldnames(requiredforexportingCSV)e.g.-f"name,age"
--fieldFile=<filename>filewithfieldnames-1perline
--type=<type>theoutputformat,eitherjsonorcsv(defaultsto'json')
-o,--out=<filename>outputfile;ifnotspecified,stdoutisused
--jsonArrayoutputtoaJSONarrayratherthanoneobjectperline
--prettyoutputJSONformattedtobehuman-readable
queryingoptions:
-q,--query=<json>queryfilter,asaJSONstring,e.g.,'{x:{$gt:1}}'
--queryFile=<filename>pathtoafilecontainingaqueryfilter(JSON)
-k,--slaveOkallowsecondaryreadsifavailable(defaulttrue)
--readPreference=<string>|<json>specifyeitherapreferencenameorapreferencejsonobject
--forceTableScanforceatablescan(donotuse$snapshot)
--skip=<count>numberofdocumentstoskip
--limit=<count>limitthenumberofdocumentstoexport
--sort=<json>sortorder,asaJSONstring,e.g.'{x:1}'
1.直接导出数据到文件中
./mongoexport-duser_center-cpassport-udev-p123456-opassport.json//摩拜单车mongodb查询语句导出以201612开头时间小于1482170579000状态为RENTAL
./bin/mongoexport-d数据库-c集合-u用户名-p密码-q'{bikeRentalStatus:"RENTAL",times:{$regex:/201612.*/i},systimes:{$lt:NumberLong(1482170579000)}}'-o1.jaon
./bin/mongoexport-duser_center-cpassport-udev-p*****-q'{_id:{$in:[171]}}'-o1.jaon
参数说明:
-h:指明数据库宿主机的IP
-u:指明数据库的用户名
-p:指明数据库的密码
-d:指明数据库的名字
-c:指明collection的名字
-f:指明要导出那些列
-o:指明到要导出的文件名
-q:指明导出数据的过滤条件
-d:指明使用的库
-c:指明要导出的集合
-o:指明要导出的文件名
从上面的结果可以看出,我们在导出数据时没有显示指定导出样式 ,默认导出了JSON格式的数据。如果我们需要导出CSV格式的数据,则需要使用–csv参数
./mongoexport-duser_center-cuser_name-udev-p123456--csv-ouser_name.json
11-20
11-19
11-20
11-20
11-20
11-19
11-20
11-20
11-19
11-20
11-19
11-19
11-19
11-19
11-19
11-19