不支持的 OP

编程入门 行业动态 更新时间:2024-10-04 05:28:49

<a href=https://www.elefans.com/category/jswz/34/1771308.html style=不支持的 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

本文发布于:2024-05-31 05:37:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1771331.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不支持   OP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!