取自https://github.com/raynaldmo/northwind-mongodb.git 練習取向不同,刪掉絕大多數的script。
# 安裝mongo-tools,才能使用mongoimport
$ sudo yum install mongo-tools
# 使用docker建置mongodb練習環境
$ docker run -d -p 0.0.0.0:27017:27017 --name northwind-mongo mongo
$ git clone https://github.com/LImoritakeU/northwind-mongodb.git
$ cd northwind-mongodb
$ npm install
# 導入資料(linux):
$ cd ./collections/json)
$ sh ../../scripts/mongo-import-json.sh
> use Northwind
> db.product.findOne()
// 出現則代表成功匯入
{
"_id" : ObjectId("5ab9ff48c0d1daae367e7b20"),
"ProductID" : "4",
"ProductName" : "Chef Anton's Cajun Seasoning",
"SupplierID" : "2",
"CategoryID" : "2",
"QuantityPerUnit" : "48 - 6 oz jars",
"UnitPrice" : "22.00",
"UnitsInStock" : "53",
"UnitsOnOrder" : "0",
"ReorderLevel" : "0",
"Discontinued" : "0"
}
接下來步驟建議手動練習,參照BT BIGDATA SOLUTION IN PRACTICE
$ cd northwind-mongodb
$ mongo Northwind scripts/N0.northwind_preProcess.js
(generate Northwind)
$ mongo Northwind N1.northwind_producting.js
$ mongo Northwind N2.northwind_orders.js
(run the script in NQ.northwind_query.js)
mongod>
//複製貼上至 mongo shell 測試 (paste code in mongo shell for testing)