不支持的 OP"/>
不支持的 OP
过去两天我一直遇到这个错误。我是节点和 MongoDB 的新手,由于这个错误,我无法继续进行。
这是我的代码供参考。
const express = require('express');
//const app = express();
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:27017/playground')
.then(() => console.log('connected to mongoDB'))
.catch(err => console.log('could not connect'))
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: 'Angular Course',
author: 'Node Learner',
tags: [ 'Angular', 'backend'],
isPublished: true
});
const result = await course.save();
console.log(result);
}
createCourse();
ok: 0,
errmsg: 'Unsupported OP_QUERY command: insert. The client driver may require an upgrade. For more details see ',
code: 352,
codeName: 'UnsupportedOpQueryCommand'
我浏览了这个错误,它总是告诉我客户端驱动程序可能需要升级。
我的node.js版本是当前的稳定版——18.12.1.
我的 npm 版本是 8.19.2
我也检查了我的网络连接并尝试了 VPN。
回答如下:显示错误的原因有两个:猫鼬版本变旧或尚未安装。 再次尝试安装猫鼬
npm i mongoose
更多推荐
不支持的 OP
发布评论