导入MongoDB示例数据

数据库NoSQL数据库技术服务知识库
场景介绍

在学习/测试 MongoDB 中,通常我们需要一定的测试数据,本文使用 mongorestore 将示例数据导入到文档数据库 MongoDB 中。

操作步骤
  1. 下载示例数据

使用如下命令将示例数据下载到具有 mongorestore 的客户端机器上

wget https://atlas-education.s3.amazonaws.com/sampledata.archive

关于示例数据的说明,可以参考文档[1]。

  1. 使用 mongorestore 进行导入

恢复 archive 形态的备份文件时,需要加上 --archive 参数

(base) [root@rudonx ~]# mongorestore --uri=mongodb://root:xxxxxx@xxxxx.mongodb.ivolces.com:3717 --drop --archive=mongo-sampledata/sampledata.archive 
2023-04-20T11:43:33.281+0800    preparing collections to restore from
2023-04-20T11:43:33.289+0800    reading metadata for sample_mflix.comments from archive 'mongo-sampledata/sampledata.archive'
2023-04-20T11:43:33.292+0800    restoring sample_mflix.comments from archive 'mongo-sampledata/sampledata.archive'
2023-04-20T11:43:33.997+0800    no indexes to restore
2023-04-20T11:43:33.997+0800    finished restoring sample_mflix.comments (41079 documents, 0 failures)
2023-04-20T11:43:34.001+0800    reading metadata for sample_training.routes from archive 'mongo-sampledata/sampledata.archive'
2023-04-20T11:43:34.005+0800    restoring sample_training.routes from archive 'mongo-sampledata/sampledata.archive'
……
2023-04-20T11:43:53.925+0800    restoring indexes for collection sample_airbnb.listingsAndReviews from metadata
2023-04-20T11:43:54.020+0800    finished restoring sample_airbnb.listingsAndReviews (3023 documents, 0 failures)
2023-04-20T11:43:54.020+0800    421053 document(s) restored successfully. 0 document(s) failed to restore.
  1. 检查导入的数据

rs-mongo-replica-8bc94b1f47ad:PRIMARY|test> show dbs
admin               0.000GB
config              0.000GB
local               0.172GB
sample_airbnb       0.053GB
sample_analytics    0.010GB
sample_geospatial   0.001GB
sample_guides       0.000GB
sample_mflix        0.041GB
sample_restaurants  0.006GB
sample_supplies     0.001GB
sample_training     0.045GB
sample_weatherdata  0.004GB
参考文档

[1] https://www.mongodb.com/docs/atlas/sample-data/

95
0
0
0
相关产品
评论
未登录
看完啦,登录分享一下感受吧~
暂无评论