提问者:小点点

无法将文档上载到我的mongoDB服务器


我在自己的node.js上学习,我在关注codewithmosh网站。问题是,我试图使用Compass上传一个新对象到我的mongo数据库。我有以下代码(见截图输出),没有错误,在Mosh'es教程中,一切都很好地工作。

问题是我的服务器没有用新文档更新。知道我错过了什么吗?

我刷新了指南针几次,什么也没变。

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();



共1个答案

匿名用户

好吧,我想出来了。我的指南针有一个错误的配置。我得去建立一个连接