5.9.2 集合导入mongoimport

5.9.2 集合导入mongoimport

数据导入mongoimport的语法格式为:

>mongoimport-d dbname-c collectionname--file filename--headerline--type json/csv-f field

参数说明:

-d:数据库名

-c:collection名

--file:要导入的文件

--type:导入的格式默认json

-f:导入的字段名

--headerline:如果导入的格式是csv,则可以使用第一行的标题作为导入的字段

例如:

>mongoimport-d test-c users--file/mongodb/articles.json--type json

上述命令表示把/mongodb/articles.json导入test数据库的users集合中,文件格式为JSON。