-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmongoose.js
36 lines (31 loc) · 892 Bytes
/
mongoose.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
const mongoose = require('mongoose');
const schema = mongoose.Schema;
const chapterSchema = schema({
title: String,
index: Number,
nbOfLessons: Number,
active: Boolean,
infos: { type: {}, default: { author: 'Nathalie' } },
});
const Chapters = mongoose.model('chapters', chapterSchema);
mongoose
.connect('mongodb://alex:[email protected]:27017/dyma', {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => {
console.log('connection OK');
Chapters.findOne({ title: 'MongoDB' });
// ------- QUERIES
Chapters.find({}, (err, docs) => {
console.log(docs);
});
// ------- CREATION
// const newChapter = new Chapters({ active: true });
// newChapter.title = 'MongoDB';
// newChapter.nbOfLessons = 15;
// newChapter.save((err, doc) => {
// console.log(doc);
// });
})
.catch((err) => console.log(err));