成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

mongodb的導(dǎo)入導(dǎo)出方法

移動(dòng)開發(fā) Android MongoDB
MongoDB提供了mongoexport工具,可以把一個(gè)collection導(dǎo)出成json格式或csv格式的文件。可以指定導(dǎo)出哪些數(shù)據(jù)項(xiàng),也可以根據(jù)給定的條件導(dǎo)出數(shù)據(jù)。工具幫助信息如下:

(mongoexport導(dǎo)出工具

MongoDB提供了mongoexport工具,可以把一個(gè)collection導(dǎo)出成json格式或csv格式的文件。可以指定導(dǎo)出哪些數(shù)據(jù)項(xiàng),也可以根據(jù)給定的條件導(dǎo)出數(shù)據(jù)。工具幫助信息如下:

  1. [root@localhost bin]# ./mongoexport --help  
  2. options:  
  3. --help produce help message   
  4. -v [ --verbose ] be more verbose (include multiple times for more   
  5. verbosity e.g. -vvvvv)   
  6. -h [ --host ] arg mongo host to connect to ( /s1,s2 for sets)   
  7. --port arg server port. Can also use --host hostname:port   
  8. --ipv6 enable IPv6 support (disabled by default)   
  9. -u [ --username ] arg username   
  10. -p [ --password ] arg password   
  11. --dbpath arg directly access mongod database files in the given   
  12. path, instead of connecting to a mongod server -   
  13. needs to lock the data directory, so cannot be used   
  14. if a mongod is currently accessing the same path   
  15. --directoryperdb if dbpath specified, each db is in a separate   
  16. directory   
  17. -d [ --db ] arg database to use   
  18. -c [ --collection ] arg collection to use (some commands)   
  19. -f [ --fields ] arg comma separated list of field names e.g. -f name,age   
  20. --fieldFile arg file with fields names - 1 per line   
  21. -q [ --query ] arg query filter, as a JSON string   
  22. --csv export to csv instead of json   
  23. -o [ --out ] arg output file; if not specified, stdout is used   
  24. --jsonArray output to a json array rather than one object per   
  25. line   
  26. [root@localhost bin]# 

下面我們將以一個(gè)實(shí)際的例子說(shuō)明,此工具的用法:

將foo庫(kù)中的表t1導(dǎo)出成json格式:

  1. [root@localhost bin]# ./mongoexport -d foo -c t1 -o /data/t1.json   
  2. connected to: 127.0.0.1   
  3. exported 1 records   
  4. [root@localhost bin]# 

導(dǎo)出成功后我們看一下/data/t1.json文件的樣式,是否是我們所希望的:

  1. root@localhost data]# more t1.json   
  2. "_id" : { "$oid" : "4f927e2385b7a6814a0540a0" }, "age" : 2 }   
  3. [root@localhost data]# 

通過(guò)以上說(shuō)明導(dǎo)出成功,但有一個(gè)問(wèn)題,要是異構(gòu)數(shù)據(jù)庫(kù)的遷移怎么辦呢?例如我們要將MongoDB的數(shù)據(jù)導(dǎo)入到MySQL該怎么辦呢?MongoDB提供 了一種csv的導(dǎo)出格式,就可以解決異構(gòu)數(shù)據(jù)庫(kù)遷移的問(wèn)題了. 下面將foo庫(kù)的t2表的age和name列導(dǎo)出, 具體如下:

  1. [root@localhost bin]# ./mongoexport -d foo -c t2 --csv -f age,name -o /data/t2.csv   
  2. connected to: 127.0.0.1   
  3. exported 1 records   
  4. [root@localhost bin]# 

查看/data/t2.csv的導(dǎo)出結(jié)果

  1. [root@localhost data]# more t2.csv   
  2. age,name   
  3. 1,"wwl"   
  4. [root@localhost data]# 

mongoimport導(dǎo)入工具

MongoDB提供了mongoimport工具,可以把一個(gè)特定格式文件中的內(nèi)容導(dǎo)入到某張collection中。工具幫助信息如下:

  1. [root@localhost bin]# ./mongoimport --help   
  2. options:   
  3. --help produce help message   
  4. -v [ --verbose ] be more verbose (include multiple times for more   
  5. verbosity e.g. -vvvvv)   
  6. -h [ --host ] arg mongo host to connect to ( /s1,s2 for sets)   
  7. --port arg server port. Can also use --host hostname:port   
  8. --ipv6 enable IPv6 support (disabled by default)   
  9. -u [ --username ] arg username   
  10. -p [ --password ] arg password   
  11. --dbpath arg directly access mongod database files in the given   
  12. path, instead of connecting to a mongod server -   
  13. needs to lock the data directory, so cannot be used   
  14. if a mongod is currently accessing the same path   
  15. --directoryperdb if dbpath specified, each db is in a separate   
  16. directory   
  17. -d [ --db ] arg database to use   
  18. -c [ --collection ] arg collection to use (some commands)   
  19. -f [ --fields ] arg comma separated list of field names e.g. -f name,age   
  20. --fieldFile arg file with fields names - 1 per line   
  21. --ignoreBlanks if given, empty fields in csv and tsv will be ignored   
  22. --type arg type of file to importdefault: json (json,csv,tsv)   
  23. --file arg file to import from; if not specified stdin is used   
  24. --drop drop collection first   
  25. --headerline CSV,TSV only - use first line as headers   
  26. --upsert insert or update objects that already exist   
  27. --upsertFields arg comma-separated fields for the query part of the   
  28. upsert. You should make sure this is indexed   
  29. --stopOnError stop importing at first error rather than continuing   
  30. --jsonArray load a json array, not one item per line. Currently   
  31. limited to 4MB. 

下面我們將以一人實(shí)際的例子說(shuō)明,此工具的用法:
先看一下foo庫(kù)中的t1表數(shù)據(jù):

  1. > db.t1.find();   
  2. "_id" : ObjectId("4f937a56450beadc560feaa9"), "age" : 5 }   

t1其中有一條age=5的記錄, 我們?cè)倏匆幌耲son文件中的數(shù)據(jù)是什么樣子的:

  1. [root@localhost data]# more t1.json   
  2. "_id" : { "$oid" : "4f937a56450beadc560feaa7" }, "age" : 8 }   
  3. [root@localhost data]# 

可以看到t1.json文件中有一條age=8的數(shù)據(jù),下面我們將用mongoimport工具將json文件中的記錄導(dǎo)入到t1表中:

  1. [root@localhost bin]# ./mongoimport -d foo -c t1 /data/t1.json   
  2. connected to: 127.0.0.1   
  3. imported 1 objects 

工具返回信息說(shuō)明向表中插入了一條記錄. 我們進(jìn)庫(kù)里實(shí)際驗(yàn)證一下:

  1. [root@localhost bin]# ./mongo   
  2. MongoDB shell version: 1.8.1   
  3. connecting to: test   
  4. > use foo   
  5. switched to db foo   
  6. > db.t1.find();   
  7. "_id" : ObjectId("4f937a56450beadc560feaa9"), "age" : 5 }   
  8. "_id" : ObjectId("4f937a56450beadc560feaa7"), "age" : 8 }   

 

責(zé)任編輯:chenqingxiang 來(lái)源: oschina
相關(guān)推薦

2011-01-18 17:05:35

Thunderbird郵件導(dǎo)入導(dǎo)出

2011-05-16 13:05:56

SQL導(dǎo)入導(dǎo)出MYSQL

2011-04-13 10:09:50

Oracle數(shù)據(jù)泵導(dǎo)入導(dǎo)出

2011-05-16 14:17:31

MySQL導(dǎo)入導(dǎo)出大量數(shù)據(jù)

2011-05-24 09:51:07

MySQLMongoDB

2020-12-23 14:18:43

JavaScript模塊導(dǎo)出

2010-08-26 16:49:09

DB2導(dǎo)入導(dǎo)出

2010-10-28 11:55:47

oracle數(shù)據(jù)導(dǎo)出

2011-07-26 13:05:06

PLSQL DevelopOracle數(shù)據(jù)庫(kù)

2019-08-25 23:30:10

mysql命令mysqldump

2023-03-28 07:17:25

場(chǎng)景數(shù)據(jù)業(yè)務(wù)

2011-07-27 15:28:10

MySQL數(shù)據(jù)庫(kù)字符編碼集

2011-04-15 10:37:53

Oracle導(dǎo)入導(dǎo)出語(yǔ)法

2019-09-05 19:28:23

Docker程序員MySQL

2012-03-22 10:23:24

Exchange 20郵箱數(shù)據(jù)

2010-11-29 13:22:45

sybase數(shù)據(jù)表

2009-11-23 10:24:22

2011-02-21 14:40:08

Foxmailoutlook數(shù)據(jù)

2010-04-22 10:16:43

2010-07-23 09:25:50

SQL Server導(dǎo)
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)

主站蜘蛛池模板: 久久精品亚洲一区 | 91久久精品日日躁夜夜躁国产 | 欧产日产国产精品v | 99精品国自产在线 | 丝袜一区二区三区 | 国产乱码精品一区二区三区忘忧草 | 久久99蜜桃综合影院免费观看 | 99精品国自产在线 | 国产黄色大片 | 欧美久久久久久 | 日韩精品免费 | 国产一区二区三区不卡av | 风间由美一区二区三区在线观看 | 久草色视频 | 观看av | 欧美精品片 | 久久伊人久久 | 国产一级淫片免费视频 | 欧美久久天堂 | 久久一区二区视频 | 午夜视频在线观看网址 | www日本在线播放 | 日韩欧美国产一区二区三区 | 国产有码| 久久99精品国产自在现线小黄鸭 | 亚洲精品自在在线观看 | 中文字幕在线视频观看 | 午夜电影网 | 999精品在线 | 嫩草视频在线看 | 亚洲国产精品va在线看黑人 | 香蕉久久av | 国产精品久久久久久久久久久久午夜片 | 女人夜夜春 | 国产精品久久精品 | caoporn免费在线视频 | 人人九九精 | 欧美黄色片 | a级毛片毛片免费观看久潮喷 | 99精品久久久久久久 | 欧美性另类 |