skip to Main Content

I stuck up with this error for the last two days. I am new to node and MongoDB and because of this error, I could not proceed further.

Here is my code for reference.

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 https://dochub.mongodb.org/core/legacy-opcode-removal',
  code: 352,
  codeName: 'UnsupportedOpQueryCommand'

I browsed about this error and it always tells me to the client driver may require an upgrade.

My node.js version is the current stable version – 18.12.1.
My npm version is 8.19.2

I also checked my network connection and tried VPN too.

2

Answers


  1. Try installing mongoose again

    npm i mongoose
    
    Login or Signup to reply.
  2. The error is showing because of two reasons either mongoose version has become old or it has not been installed yet .
    try installing mongoose again

    npm i mongoose

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search