-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatebase.js
More file actions
42 lines (36 loc) · 1.05 KB
/
Copy pathdatebase.js
File metadata and controls
42 lines (36 loc) · 1.05 KB
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
const mongo = require("mongoose");
module.exports = class {
constructor() {
main().catch(err => console.log(err));
async function main() {
await mongo.connect('mongodb://127.0.0.1:27017/todolistDB');
};
const itemsSchema = new mongo.Schema({
name: String
});
this.Item = mongo.model("Item", itemsSchema);
const listSchema = new mongo.Schema({
name: String,
items: [itemsSchema]
});
this.List = mongo.model("List", listSchema);
};
inserirVarios(array) {
this.Item.insertMany(array)
.then((event) => {
console.log("Seu array foi adicionado! ");
})
.catch((err) => {
console.log(err);
});
};
deletaUm(id) {
this.Item.deleteOne({ _id: id })
.then((event) => {
console.log("Seu item foi deletado " + event);
})
.catch((err) => {
console.log(err);
});
};
};