是否有适用于 MySql 的示例 MongoDB 数据库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5723896/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 12:04:26  来源:igfitidea点击:

Is there a sample MongoDB Database along the lines of world for MySql?

mongodb

提问by Amol Katdare

As someone new to Mongo, I am looking for a sample MongoDB database that I can import and play with. Something along the lines of worldfor mysql or Northwindfor MSSQL.

作为 Mongo 的新手,我正在寻找一个可以导入和使用的示例 MongoDB 数据库。类似于mysql的世界或MSSQL 的Northwind

Is there one? (I couldn't find any reference to one at http://www.mongodb.orgnor did my googling help)

有吗?(我在http://www.mongodb.org 上找不到任何参考资料,我的谷歌搜索也没有帮助)

采纳答案by Muzzamil Hussain

For *NIX/Mac OS this can be done in two simple steps

对于 *NIX/Mac OS,这可以通过两个简单的步骤完成

wget http://media.mongodb.org/zips.json
mongoimport -v --file=zips.json

For Windows users: Please follow the following steps to import from the json file if you are using windows 7:

对于 Windows 用户:如果您使用的是 Windows 7,请按照以下步骤从 json 文件中导入:

  • Download the above mentioned JSON fileand place it inside a folder (say d:\sample)
  • Open a command prompt, start the mongo server by going in to the bin directory and typing in mongoD
  • Now take another command prompt and go to the bin directory again and write the following command

    C:\mongodb\bin>mongoimport --db test --collection zips --file d:\sample\zips.json

  • The import should start working immediately and at the end it should show something like this : Thu Dec 19 17:11:22 imported 29470 objects

  • 下载上面提到的JSON 文件并将其放在一个文件夹中(比如d:\sample
  • 打开命令提示符,通过进入 bin 目录并键入来启动 mongo 服务器 mongoD
  • 现在采取另一个命令提示符并再次转到 bin 目录并编写以下命令

    C:\mongodb\bin>mongoimport --db test --collection zips --file d:\sample\zips.json

  • 导入应立即开始工作,最后应显示如下内容:Thu Dec 19 17:11: 22imported 29470 objects

That's it!

就是这样!

回答by sirfilip

I found thisyou can import the json data with:

我发现这个你可以导入JSON数据:

mongoimport --db scratch --collection zips --file zips.json

I guess that you can import any json data that you find, it also supports csv and tsv. Hope this helps.

我想您可以导入您找到的任何 json 数据,它还支持 csv 和 tsv。希望这可以帮助。

回答by tslater

This doesn't have everything, but it is a nice step towards getting Northwind on MongoDB:

这并不是所有的东西,但它是在 MongoDB 上获得 Northwind 的一个很好的步骤:

https://github.com/tmcnab/northwind-mongo

https://github.com/tmcnab/northwind-mongo

回答by AzizSM

Download the collection of Northwind csv files from https://github.com/tmcnab/northwind-mongo/archive/master.zip

https://github.com/tmcnab/northwind-mongo/archive/master.zip下载 Northwind csv 文件的集合

Execute following command to import csv into mongodb

执行以下命令将csv导入mongodb

mongoimport -d Northwind -c categories --type csv --file categories.csv --headerline
mongoimport -d Northwind -c customers --type csv --file customers.csv --headerline
mongoimport -d Northwind -c employee-territories --type csv --file employee-territories.csv --headerline
mongoimport -d Northwind -c employees --type csv --file employees.csv --headerline
mongoimport -d Northwind -c northwind --type csv --file northwind.csv --headerline
mongoimport -d Northwind -c order-details --type csv --file order-details.csv --headerline
mongoimport -d Northwind -c orders --type csv --file orders.csv --headerline
mongoimport -d Northwind -c products --type csv --file products.csv --headerline
mongoimport -d Northwind -c regions --type csv --file regions.csv --headerline
mongoimport -d Northwind -c shippers --type csv --file shippers.csv --headerline
mongoimport -d Northwind -c suppliers --type csv --file suppliers.csv --headerline
mongoimport -d Northwind -c territories --type csv --file territories.csv --headerline

This can be used for both Windows and Liinux OS

这可用于 Windows 和 Linux 操作系统

回答by Ostati

After downloading Northwinddata as per @tslater, I cleaned it up a bit..

按照@tslater下载Northwind数据后,我对其进行了一些清理。

And ran the following PowerShell command to import into the mongo:

并运行以下 PowerShell 命令以导入 mongo:

Get-ChildItem "C:\MongoDb\samples\northwind\csv" -Filter *.csv | `
Foreach-Object {
    C:\MongoDb\bin\mongoimport.exe -h localhost:55000 -d northwind -c $_.BaseName --type csv --file $_.FullName --headerline 
}

回答by Rahul Saini

http://docs.mongodb.org/manual/tutorial/aggregation-zip-code-data-set/provides a json file at the link : http://media.mongodb.org/zips.jsonwhich is zip code data.

http://docs.mongodb.org/manual/tutorial/aggregation-zip-code-data-set/在链接上提供了一个 json 文件:http: //media.mongodb.org/zips.json这是邮政编码数据.

This can be used for Map-Reduce, Aggregation and Grouping queries learning purposes and the above tutorial link at MongoDB also shows how.

这可用于 Map-Reduce、Aggregation 和 Grouping 查询学习目的,MongoDB 上的上述教程链接也显示了如何操作。

For Windows: You can install a MongoVUE tool (from http://www.mongovue.com) , which is IDE for MongoDB shell operations and also provides Map-Reduce, Aggregation and Filtering support as well as data import from MySQL databases to MongoDB.

对于 Windows:您可以安装一个 MongoVUE 工具(来自http://www.mongovue.com),它是 MongoDB shell 操作的 IDE,还提供 Map-Reduce、聚合和过滤支持以及从 MySQL 数据库到 MongoDB 的数据导入.

The JSON file at the link above has 3 duplicate _id entries which will hinder the import process a bit and you may have to do removeall for inserted documents. But in the end you should have 29,467 documents in your collection.

上面链接中的 JSON 文件有 3 个重复的 _id 条目,这会稍微阻碍导入过程,您可能必须对插入的文档执行 removeall。但最终您的集合中应该有 29,467 个文档。

MongoVUE IDE after the import

导入后的 MongoVUE IDE

回答by metdos

You can create TPC-Hbenchmark data-sets and import them.

您可以创建TPC-H基准数据集并导入它们。

Example import for lineitem table:

lineitem 表的导入示例:

./mongoimport -d test -c lineitem --type csv -f  l_orderkey,l_partkey,l_suppkey,l_linenumber,l_quantity,l_extendedprice,l_discount,l_tax,l_returnflag,l_linestatus,l_shipdate,l_commitdate,l_receiptdate,l_shipinstruct,l_shipmode,l_comment --file /home/metdos/mongo/tpc-h/tpch_2_13_0/lineitem.tbl

回答by Parvesh Kumar Tandon

I am updating movies collection, whenever get free time. Personally it is very useful for me as it contains embedded object, array field, string field, date field. Click here to get JSON file of movie collection

我正在更新电影收藏,只要有空闲时间。就我个人而言,它对我非常有用,因为它包含嵌入对象、数组字段、字符串字段、日期字段。单击此处获取电影收藏的JSON 文件

Demo of one document

一个文档的演示

{
    "_id" : ObjectId("5692a15524de1e0ce2dfcfa3"),
    "title" : "Toy Story 4",
    "year" : 2011,
    "rated" : "G",
    "released" : ISODate("2010-06-18T04:00:00.000Z"),
    "runtime" : 206,
    "countries" : [ 
        "USA"
    ],
    "genres" : [ 
        "Animation", 
        "Adventure", 
        "Comedy"
    ],
    "director" : "Lee Unkrich",
    "writers" : [ 
        "John Lasseter", 
        "Andrew Stanton", 
        "Lee Unkrich", 
        "Michael Arndt"
    ],
    "actors" : [ 
        "Tom Hanks", 
        "Tim Allen", 
        "Joan Cusack", 
        "Ned Beatty"
    ],
    "plot" : "The toys are mistakenly delivered to a day-care center instead of the attic right before Andy leaves for college, and it's up to Woody to convince the other toys that they weren't abandoned and to return home.",
    "poster" : "http://ia.media-imdb.com/images/M/MV5BMTgxOTY4Mjc0MF5BMl5BanBnXkFtZTcwNTA4MDQyMw@@._V1_SX300.jpg",
    "imdb" : {
        "id" : "tt0435761",
        "rating" : 8.4,
        "votes" : 500084
    },
    "tomato" : {
        "meter" : 99,
        "image" : "certified",
        "rating" : 8.9,
        "reviews" : 287,
        "fresh" : 283,
        "consensus" : "Deftly blending comedy, adventure, and honest emotion, Toy Story 3 is a rare second sequel that really works.",
        "userMeter" : 89,
        "userRating" : 4.3,
        "userReviews" : 602138
    },
    "metacritic" : 92,
    "awards" : {
        "wins" : 56,
        "nominations" : 86,
        "text" : "Won 2 Oscars. Another 56 wins & 86 nominations."
    },
    "type" : "movie",
    "reviews" : [ 
        {
            "date" : ISODate("2017-02-13T04:00:00.000Z"),
            "name" : "parvesh",
            "rating" : 8.9,
            "comment" : "My first review for Toy Story 3, hoping it will execute while trying for the very first time."
        }, 
        {
            "date" : ISODate("2017-02-13T04:00:00.000Z"),
            "name" : "Prabhash",
            "rating" : 9.3,
            "comment" : "My second review for Toy Story 3, hoping it will execute while trying for the very first time."
        }, 
        {
            "date" : ISODate("2017-02-11T04:00:00.000Z"),
            "name" : "praveen",
            "rating" : 6.7,
            "comment" : "My third review for Toy Story 3, hoping it will execute while trying for the very first time."
        }
    ]
}