加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

03-【MongoDB入门教程】导入数据

发布时间:2020-12-13 13:41:04 所属栏目:百科 来源:网络整理
导读:导入数据 本教程使用test数据库和restaurants集合为例进行讲解。下面是restaurants的一个文档结构示例: { "address": { "building": "1007","coord": [ -73.856077,40.848447 ],"street": "Morris Park Ave","zipcode": "10462" },"borough": "Bronx","cuis

导入数据

本教程使用test数据库和restaurants集合为例进行讲解。下面是restaurants的一个文档结构示例:

{
  "address": {
     "building": "1007","coord": [ -73.856077,40.848447 ],"street": "Morris Park Ave","zipcode": "10462"
  },"borough": "Bronx","cuisine": "Bakery","grades": [
     { "date": { "$date": 1393804800000 },"grade": "A","score": 2 },{ "date": { "$date": 1378857600000 },"score": 6 },{ "date": { "$date": 1358985600000 },"score": 10 },{ "date": { "$date": 1322006400000 },"score": 9 },{ "date": { "$date": 1299715200000 },"grade": "B","score": 14 }
  ],"name": "Morris Park Bake Shop","restaurant_id": "30075445"
}

导入例子数据

在进行操作之前,我们需要例子数据,在这里下载数据文件dataset.json。

导入数据到集合

在命令行中执行mongoimport命令将上面下载的数据文件中的数据导入到test数据库的restaurants集合中。如果此集合已经存在,下面的操作会先删除。

mongoimport --db test --collection restaurants --drop --file C:datadataset.json

mongoimport命令连接到本机运行的mongod实例,如果要把数据导到不同主机,不同端口的实例,可以指定主机和端口,使用参数 --host--port

数据导入后,你可以用mongo命令连接到实例,使用show dbsuse testshow collectionsdb.restaurants.find()命令查看导入的数据。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读