嘿,这让我发疯了。我有这段代码,期望的目标是使用给定的属性创建一个Author。我已经运行了诸如mongodb的指南针和mongod之类的所有内容,并且在出现此错误之后,我更新了npm +节点。还是一个错误。
代码在这里:
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/playground')
.then(() => console.log('Connected to MongoDB...'))
.catch(err => console.error('Could not connect to MongoDB...', err));
const authorSchema = new mongoose.Schema({
name: String,
bio: String,
website: String,
})
const courseSchema = new mongoose.Schema({
name: String
})
const Author = mongoose.model('Author', authorSchema)
const Course = mongoose.model('Course',courseSchema)
async function createAuthor(name, bio, website) {
const author = new Author({
name,
bio,
website
});
const result = await author.save();
console.log(result);
}
async function createCourse(name, author) {
const course = new Course({
name,
author
});
const result = await course.save();
console.log(result);
}
async function listCourses() {
const courses = await Course
.find()
.select('name');
console.log(courses);
}
createAuthor('Mosh', 'My bio', 'My Website');
// createCourse('Node Course', 'authorId')
// listCourses();
给定的错误在这里:
|| (selector['mapreduce'] && selector.out = 'inline')) {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ReferenceError: Invalid left-hand side in assignment
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:617:28)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at /Users/eesamunir/node_modules/mongodb/lib/mongodb/index.js:29:17
答案 0 :(得分:1)
由于该错误不会在您的代码中发生,因此它必须是猫鼬的一种错误。看起来SyntaxError已被修复,因此只需使用以下命令获取新的修复版本:
npm install mongoose