This repository has been archived by the owner on Dec 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateDB.js
88 lines (78 loc) · 2.73 KB
/
createDB.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/parfum";
MongoClient.connect(url, { useNewUrlParser: true }, function (err, db) {
if (err) throw err;
console.log("Database created!");
db.close();
MongoClient.connect("mongodb://localhost:27017/", { useNewUrlParser: true }, function (err, db) {
if (err) throw err;
var dbo = db.db("parfum");
dbo.createCollection("teams", function (err, res) {
if (err) throw err;
console.log("Collection teams created!");
dbo.createCollection("teamAttempts", function (err, res) {
if (err) throw err;
console.log("Collection teamAttempts created!");
db.close();
//testTeam
MongoClient.connect("mongodb://localhost:27017/", { useNewUrlParser: true }, function (err, db) {
if (err) throw err;
var dbo = db.db("parfum");
var team = { name: "Hony" };
dbo.collection("teams").insertOne(team, function (err, res) {
if (err) throw err;
console.log("added team");
db.close();
});
var teamAttempt0 = {
teamName: "Hony",
try: 0,
originalIngredients: ['Bergamont', 'Fialka', 'Ibišek', 'Ibišek'],
inputIngredients: ['Kosatec', 'Vanilka', 'Rozmarýn', 'Ibišek'],
result: { '0': 'miss', '1': 'miss', '2': 'miss', '3': 'critical-hit' }
};
var teamAttempt1 = {
teamName: "Hony",
try: 0,
originalIngredients: ['Bergamont', 'Fialka', 'Ibišek', 'Ibišek'],
inputIngredients: ['Bergamont', 'Fialka', 'Rozmarýn', 'Ibišek'],
result: { '0': 'miss', '1': 'miss', '2': 'miss', '3': 'critical-hit' }
};
dbo.collection("teamAttempts").insertOne(teamAttempt0, function (err, res) {
if (err) throw err;
console.log("added teamAttempt0");
db.close();
});
dbo.collection("teamAttempts").insertOne(teamAttempt1, function (err, res) {
if (err) throw err;
console.log("added teamAttempt1");
db.close();
});
});
//end testTeam
});
});
});
});
setTimeout(function () {
//print data form
MongoClient.connect(url, { useNewUrlParser: true }, function (err, db) {
if (err) throw err;
var dbo = db.db("parfum");
dbo.collection('teams').aggregate([
{
$lookup:
{
from: 'teamAttempts',
localField: 'name',
foreignField: 'teamName',
as: 'attempts'
}
}
]).toArray(function (err, res) {
if (err) throw err;
console.log(JSON.stringify(res));
db.close();
});
});
}, 2000);