MongoDB数据库导入数据(非常详细)

前面的博客已经完成了数据库环境搭建、创建集合和创建文档,现在下面是对MongoDB导入数据库的详细介绍,希望可以帮助到有需要的小伙伴~

把大量数据导入数据库中:
mongoimport -d 数据库名称 -c 集合名称 -file 要导入的数据文件

找到mongodb数据库的安装目录,将安装目录下的bin目录放置在环境变量中。

如果bin目录里面少.exe文件,下面的链接里有bin目录下的所有.exe文件,下载然后复制到bin目录下就可以了
链接
https://www.mongodb.com/try/download/database-tools?tck=docs_databasetools

user.json文件:

[{
     
    "name":"zhangsan",
    "age":"18",
    "email":"[email protected]",
    "password":"123456",
    "hobbies":["sing","dance"]
},

{
     
    "name":"lisi",
    "age":"25",
    "email":"[email protected]",
    "password":"213456",
    "hobbies":["sing","dance","basketball"]
},

{
     
    "name":"wangwu",
    "age":"33",
    "email":"[email protected]",
    "password":"312456",
    "hobbies":["sing","basketball"]
},

{
     
    "name":"lucy",
    "age":"46",
    "email":"[email protected]",
    "password":"312456",
    "hobbies":["sing","basketball","睡觉"]
},

{
     
    "name":"mary",
    "age":"56",
    "email":"[email protected]",
    "password":"312456",
    "hobbies":["sing","basketball","吃饭"]
},

{
     
    "name":"jenny",
    "age":"46",
    "email":"[email protected]",
    "password":"312456",
    "hobbies":["sing","basketball","睡觉","吃饭"]
}
]

在命令行工具中输入:

mongoimport -d playground -c users --file ./user.json

在这里插入图片描述

在MongoDB中,刷新:

MongoDB数据库导入数据(非常详细)_第1张图片

end~

你可能感兴趣的:(MongoDB)