-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.js
More file actions
25 lines (18 loc) · 753 Bytes
/
Copy pathmodels.js
File metadata and controls
25 lines (18 loc) · 753 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
const mongoose = require('mongoose');
const URI = "mongodb+srv://olenadanykh:31Lenok543542@cluster0-wtt28.mongodb.net/test?retryWrites=true&w=majority";
mongoose.connect(URI, { useUnifiedTopology: true, useNewUrlParser: true }, (err) => {
if (err) return {books: {err: 'Error from mongoose.connect'}}
console.log('Connected to MongoDB')
});
const Schema = mongoose.Schema;
const booksSchema = new Schema({
title: String,
author: String,
pages: Number
});
// creats a model for the 'books' collection that will be part of the export
const Books = mongoose.model('Books', booksSchema);
// exports all the models in an object to be used in the controller
module.exports = {
Books
}