-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
57 lines (49 loc) · 1.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
const mongoose = require('mongoose');
mongoose.connect("mongodb://localhost:27017/fruitsDB", {useNewUrlParser: true});
const fruitSchema = new mongoose.Schema({
name: {
type: String,
required: [true, "Please check data entry, no name"]
},
rating: {
type:Number,
min: 1,
max:10
},
review: String
});
const Fruit = mongoose.model("Fruit", fruitSchema);
const fruit = new Fruit ({
name: "Apple",
rating: 4,
review: "totaly overated"
});
//fruit.save();
const personSchema = new mongoose.Schema({
name:String,
age: Number
});
const Person = mongoose.model("Person",personSchema);
const person = new Person({
name: "John",
age: 37
})
person.save();
const findDocuments = function(db, callback){
const collection = db.collection('fruits');
collection.find({}).toArray(function(err, fruits){
assert.equal(err,null);
console.log("wtf");
})
};
Fruit.find(function(err, fruits){
if (err){
console.log(err);
}else{
mongoose.connection.close();
fruits.forEach(function(fruit){
console.log(fruit.name);
});
}
});
n