对于MySql,是否有一个样本的MongoDB数据库?

时间:2011-04-19 23:23:11

标签: mongodb

作为Mongo的新手,我正在寻找一个可以导入和使用的示例MongoDB数据库。 对于mysql来说world或对于MSSQL来说都是Northwind

有吗? (我在http://www.mongodb.org找不到任何一个引用,也没有找到我的谷歌搜索帮助)

8 个答案:

答案 0 :(得分:56)

我发现this您可以使用以下内容导入json数据:

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

我猜你可以导入你找到的任何json数据,它也支持csv和tsv。希望这会有所帮助。

答案 1 :(得分:47)

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

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

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

  • 下载上述JSON file并将其放入文件夹(例如d:\sample
  • 打开命令提示符,进入bin目录并键入mongoD
  • 启动mongo服务器
  • 现在再次执行命令提示符并再次转到bin目录并编写以下命令

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

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

就是这样!

答案 2 :(得分:17)

这并不是一切,但它是朝着MongoDB获取Northwind的一个很好的一步:

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

答案 3 :(得分:10)

https://github.com/tmcnab/northwind-mongo/archive/master.zip

下载Northwind csv文件集合

执行以下命令将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

这可以用于Windows和Liinux OS

答案 4 :(得分:7)

根据@tslater下载Northwind数据后,我清理了一下......

并运行以下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 
}

答案 5 :(得分:3)

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

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

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

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

MongoVUE IDE after the import

答案 6 :(得分:2)

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

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

答案 7 :(得分:0)

我正在更新电影收藏,每当有空闲时间。 就个人而言,它对我来说非常有用,因为它包含嵌入对象,数组字段,字符串字段,日期字段。单击此处获取movie collection

的JSON文件

演示一个文件

{
    "_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."
        }
    ]
}