导入(import)
概念
把一个JSON格式或者CSV格式的文件导入为mongodb的collection。
语法
mongoimport -d dbName -c collectionName --type json/csv -f fields --file filename
参数说明:
-d: 数据库名
-c: collection名
--type: 导入文件的格式
-f: 导入的字段名
--fieldFile: 可直接导入整个文件
--file: 要导入的文件
--headerline:仅适用于导入csv,tsv格式的数据,表示文件中的第一行作为数据头
示例
mongoimport -d test -c posts --type csv -f "_id,content,date,title" --file post.csv
导出(export)
概念
把mongodb的collection导出为JSON格式或者CSV格式的文件。
语法
mongoexport -d dbName -c collectionName --type json/csv -f fields -o filename
参数说明:
-d: 数据库名
-c: collection名
--type: 导出文件的格式
-f: 导出的字段名
-o: 要导出文件的名字
示例
mongoexport -d tables -c posts --type csv -f "_id,content,date,title" -o post.csv
默认导出路径在bin目录下,也可修改导出文件路径,如
mongoexport -d tables -c posts --type csv -f "_id,content,date,title" -o D:/post.csv
如果不想通过输入命令行的方式操作的话,也可安装mongodb可视化工具,如Studio 3T
网友评论