-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
109 lines (80 loc) · 2.07 KB
/
app.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
const mongoose = require("mongoose");
mongoose.connect("mongodb://localhost:27017/FruitsDB");
const FruitSchema = new mongoose.Schema ({
name: String,
rating : Number,
review : String
});
const Fruit = mongoose.model("Fruit", FruitSchema);
const fruit = new Fruit({
name : "apple",
rating : 7,
review : "Taste good"
})
// const PerSchema = new mongoose.Schema ({
// name : String,
// age : Number
// });
// const Person = mongoose.model("Person", PerSchema);
// // const person = new Person({
// // name : "Rajesh",
// // age : 34
// // })
// person.save();
const kiwi = new Fruit({
name:"Kiwwi",
score : 8,
review : "It was great"
})
kiwi.save();
const Grapes = new Fruit({
name:"Grapes",
score : 8,
review : "It was good"
})
Grapes.save();
Fruit.find(function(err,fruits){
if(err){
console.log(err);
}else{
console.log(fruits);
}
})
// fruit.save();
// const url = 'mongodb://localhost:27017';
// const dbName = 'FruitsDB';
// const client = new MongoClient(url);
// client.connect(function(err) {
// assert.equal(null,err);
// console.log("Server connected sucessftully");
// const db = client.db(dbName);
// insertDocuments(db,function(){
// client.close()
// });
// });
// const insertDocuments = function(db,callback) {
// const collection = db.collection('fruits');
// collection.insertMany([
// {
// name : "Apple",
// score : 8,
// review : "Great fruit"
// }
// , {
// name :" Grapes",
// score :5,
// review : "good"
// }
// ,{
// name : "GreenApple",
// score : 10,
// review : "Excellent"
// }
// ], function(err,result) {
// assert.equal(err,null);
// // assert.equal(3, result);
// // assert.equal(3, result.ops.length);
// console.log("Inserted 3 document into cillection");
// callback(result);
// });
// }