使用 JSON 进行 mongoimport
zipcodes.json 中的示例 zipcode 数据集存储在 c:\ Users \ yc03ak1 \ Desktop \ zips.json 中
{ "_id" : "01001", "city" : "AGAWAM", "loc" : [ -72.622739, 42.070206 ], "pop" : 15338, "state" : "MA" }
{ "_id" : "01002", "city" : "CUSHMAN", "loc" : [ -72.51564999999999, 42.377017 ], "pop" : 36963, "state" : "MA" }
{ "_id" : "01005", "city" : "BARRE", "loc" : [ -72.10835400000001, 42.409698 ], "pop" : 4546, "state" : "MA" }
{ "_id" : "01007", "city" : "BELCHERTOWN", "loc" : [ -72.41095300000001, 42.275103 ], "pop" : 10579, "state" : "MA" }
{ "_id" : "01008", "city" : "BLANDFORD", "loc" : [ -72.936114, 42.182949 ], "pop" : 1240, "state" : "MA" }
{ "_id" : "01010", "city" : "BRIMFIELD", "loc" : [ -72.188455, 42.116543 ], "pop" : 3706, "state" : "MA" }
{ "_id" : "01011", "city" : "CHESTER", "loc" : [ -72.988761, 42.279421 ], "pop" : 1688, "state" : "MA" }
将此数据集导入名为 test
的数据库和名为 zips
的集合
C:\Users\yc03ak1>mongoimport --db test --collection "zips" --drop --type json --host "localhost:47019" --file "c:\Users\yc03ak1\Desktop\zips.json"
- --db:要导入数据的数据库的名称
- --collection:数据库中要对数据进行压缩的集合的名称
- --drop:在导入之前先删除集合
- --type:需要导入的文档类型。默认 JSON
- --host:要导入数据的 mongodb 主机和端口。
- --file:json 文件所在的路径
输出:
2016-08-10T20:10:50.159-0700 connected to: localhost:47019
2016-08-10T20:10:50.163-0700 dropping: test.zips
2016-08-10T20:10:53.155-0700 [################........] test.zips 2.1 MB/3.0 MB (68.5%)
2016-08-10T20:10:56.150-0700 [########################] test.zips 3.0 MB/3.0 MB (100.0%)
2016-08-10T20:10:57.819-0700 [########################] test.zips 3.0 MB/3.0 MB (100.0%)
2016-08-10T20:10:57.821-0700 imported 29353 documents