Import Example Dataset

Overview

The examples in this guide use the restaurants collection in the test database.

The following is a sample document in the restaurants collection:

{
  "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 }, "grade": "A", "score": 6 }, { "date": { "$date": 1358985600000 }, "grade": "A", "score": 10 }, { "date": { "$date": 1322006400000 }, "grade": "A", "score": 9 }, { "date": { "$date": 1299715200000 }, "grade": "B", "score": 14 } ], "name": "Morris Park Bake Shop", "restaurant_id": "30075445" }

Use the following procedure to populate the restaurants collection.            populate vt. 居住于;构成人口;移民于;殖民于

 

Prerequisites

You must have a running mongod instance in order to import data into the database.

 

 

Procedure

Retrieve the restaurants data.

Retrieve the dataset from https://raw.githubusercontent.com/mongodb/docs-assets/primer-dataset/primer-dataset.json and save to a file named primer-dataset.json.

复制链接,直接放到迅雷里面下载

 

Import data into the collection.

In the system shell or command prompt, use mongoimport to insert the documents into the restaurants collection in the test database.

If the collection already exists in the test database, the operation will drop the restaurants collection first.

mongoimport --db test --collection restaurants --drop --file ~/downloads/primer-dataset.json

 

The mongoimport connects to a mongod instance running on localhost on port number 27017.

The--file option provides the path to the data to import, in this case, ~/downloads/primer-dataset.json.

To import data into a mongod instance running on a different host or port, specify the hostname or port by including the --host and the --port options in your mongoimport command.

 

F:\DataBase\MongoDB\test>mongoimport --db test --collection restaurants --drop -
-file ../primer-dataset.json
2017-02-28T18:43:05.680+0800 connected to: localhost
2017-02-28T18:43:05.694+0800 dropping: test.restaurants
2017-02-28T18:43:07.160+0800 imported 25359 documents

 

转载于:https://www.cnblogs.com/chucklu/p/6480297.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值