I am trying to add multiple in createCourse() method, but in mongoDB compass it adds a array in MongoDB compass. The output of the mongodb compass gives an objet containing _id, tags, data and __v. How to handle this?
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/playground')
.then(() => console.log('Connected with MongoDB...'))
.catch(err => console.log("Couldn't connect with MongoDB!!!", err));
const courseSchema = new mongoose.Schema({
name: String,
author: String,
edition: Number,
tags: [ String ],
data: {type: Date, default: Date.now},
isPublished: Boolean
})
const Course = mongoose.model('Course', courseSchema);
async function createCourse() {
const course = new Course([{
name: "Node Course",
author: "Ammar Siddiqi",
edition: 3,
tags: ['node', 'backend', 'server'],
isPublished: true
},{
name: "React Course",
author: "Mosh",
edition: 3,
tags: ['Functionalties', 'frontend', 'server'],
isPublished: true
}]);
const result = await course.save();
console.log(result);
}
createCourse();```