-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbIneteraction.js
More file actions
58 lines (38 loc) · 987 Bytes
/
dbIneteraction.js
File metadata and controls
58 lines (38 loc) · 987 Bytes
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
var mongoose = require('mongoose');
//connect to db
mongoose.connect("mongodb://localhost/cat_app",{useNewUrlParser: true ,useUnifiedTopology: true});
// this defines how the cat will look
var catSchema = new mongoose.Schema({
name: String,
age: Number,
color: String
});
var Cat = mongoose.model("Cat", catSchema);
var _1Cat = new Cat ({
name: "George",
age: 11,
color: "black"
});
_1Cat.save(function (err , cat){
if(err){
console.log("something went wrong");
}else{
console.log("just saved "+_1Cat["name"]+" to db");
console.log(cat);
}
})
Cat.create({
name : "snowhite",
age: 15,
Temp : 'Bland'
});
Cat.find({},(err, cats)=>{
if (err) {
console.log("ho no");
}else{
console.log(cats);
}
})
//add a cat to db
//retrieve all cats
//retrieve specific cat