Reputation: 43
I am studying on my own node.js and I am following codewithmosh website. The thing is, is that I try to upload a new object to my mongo database using compass. I have the following code (see screenshots for outputs) and there is no error and on mosh'es tutorial everything is working great.
The problem I have is that my server isn't being updated with the new document. Any idea what I am missing?
I refreshed the compass a few times and nothing changes.
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/playground', { useNewUrlParser: true , useUnifiedTopology: true}).then(() =>
console.log('connected to MongoDB')
).catch((err) => console / log('Could not connect to MongoDB', err));
const courseSchema = new mongoose.Schema({
name: String,
author:String,
tags: [String],
date: {type: Date, default: Date.now},
isPublished: Boolean
})
const Course = mongoose.model('Course', courseSchema);
async function createCourse () {
const course = new Course ({
name: 'node.js Course',
author: 'Daniel',
tags: ['node', 'backend'],
isPublished: true,
});
const result = await course.save();
console.log(result);
}
createCourse();
Upvotes: 0
Views: 122
Reputation: 43
OK I figure it out. There was a bad configuration in my compass. I had to go to setup a connection
Upvotes: 1