node.js - 无法将文档上传到我的 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();
解决方案
好的,我想通了。我的指南针配置错误。我不得不去建立一个连接
推荐阅读
- python - 为什么我的带有 PRAW 的 Reddit 机器人返回意外的字母字符串?
- javascript - 对象作为 React 子级无效(API、JSON)
- javascript - 蚂蚁设计表单initialValue如何使用
- javascript - 使用 jQuery 添加到购物车
- python-3.x - 使用 python3 将数据从 sqlite3 转换为 csv、xml 的问题
- spring-boot - Spring Boot 与 Spring Cloud 的兼容性
- java - 切换活动时 Android Studio 崩溃
- python - python:根据数据框中的位置对特定行值求和
- jsf - 目标不可达,标识符“searchBean”解析为空
- python - 如何查看 Autogluon 训练的模型的详细信息?