【发布时间】:2020-08-30 02:17:48
【问题描述】:
谁能帮帮我。我试图理解为什么我无法在 mongoDb 上更新我的数据库......谁能告诉我代码出了什么问题? 在此先感谢各位。
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/mongo-exercises', {
useNewUrlParser: true,
useUnifiedTopology: true
})
.then(() => console.log('Connected to MongoDb'))
.catch(() => console.log('Connected Fails!!!', err));
const exerciseSchema = new mongoose.Schema({
name: String,
author: String,
tags: [String],
date: Date,
isPublished: Boolean,
price: Number
});
const Exercicio = mongoose.model('Course', exerciseSchema);
async function updaterCourse(id) {
const exercise = await Exercicio.findByIdAndUpdate(id, {
$set: {
isPublished: true,
author: 'ANOTHER'
}
});
console.log(exercise);
}
updaterCourse("5a68ff090c553064a218a547");
【问题讨论】:
-
数据库中的记录有没有更新?
标签: javascript node.js mongodb express mean-stack