-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (36 loc) · 945 Bytes
/
index.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
const mongoose = require('mongoose')
require('dotenv').config()
mongoose.connect(
process.env.mongoUrl,
{useNewUrlParser : true, useUnifiedTopology: true}
)
// const db = mongoose.connection;
// db.on('error', console.error.bind(console, 'connection error:'));
// db.once('open', function() {
// console.log('connected')
// });
const fruitsSchema = new mongoose.Schema({
ratings : Number,
name : String,
review : String
})
const Fruit = mongoose.model("fruits", fruitsSchema)
// const fruit = new Fruit({
// name : "apple", ratings:7, review:"good"
// })
// fruit.save()
// const other = new Fruit({
// name : "mango", ratings:10, review:"awesome"
// })
// other.save()
Fruit.find((err, fruits) => {
if(err){
console.log(err)
} else {
console.log(fruits)
fruits.forEach(element => {
console.log(element.name)
});
mongoose.connection.close();
}
})