Home > Mobile >  MongoError: Unsupported OP_QUERY command: insert
MongoError: Unsupported OP_QUERY command: insert

Time:10-17

I have been new to MongoDB and I am trying to connect mongodb using nodejs application. whenever i try to run the nodejs file an error is being raised. MongoError: Unsupported OP_QUERY command: insert. The client driver may require an upgrade. For more details see https://dochub.mongodb.org/core/legacy-opcode-removal

const MongoClient = require('mongodb').MongoClient;
const assert = require('assert');

const url = 'mongodb://localhost:27017';
const dbName = 'conFusion';

const client = new MongoClient(url);

client.connect()
.then((client) => {
    console.log('Connected correctly to server');
    const db = client.db(dbName);
    const collection = db.collection('dishes');
    collection.insertOne({name: "Uthapizza", description: "test"})
    .then((result) => {
        console.log('Insert Document:\n', result.ops);
        return collection.find({}).toArray();
    })
    .then((docs) => {
        console.log('Found Documents:\n', docs);
        return collection.deleteMany({});
    })
    .then((result) => {
        console.log('Deleted Documents:\n', result);
        return client.close();
    })
    .catch((err) => console.log(err));
})

I have been using mongoDB latest version 6.0 and i am not able to perform the insertion operation using my node application.

Connected correctly to server
MongoError: Unsupported OP_QUERY command: insert. The client driver may require an upgrade. For more details see https://dochub.mongodb.org/core/legacy-opcode-removal
    at C:\Users\koushik\OneDrive\Desktop\Nodejs\node-mongo\node_modules\mongodb-core\lib\connection\pool.js:593:63
    at authenticateStragglers (C:\Users\koushik\OneDrive\Desktop\Nodejs\node-mongo\node_modules\mongodb-core\lib\connection\pool.js:516:16)
    at Connection.messageHandler (C:\Users\koushik\OneDrive\Desktop\Nodejs\node-mongo\node_modules\mongodb-core\lib\connection\pool.js:552:5)
    at emitMessageHandler (C:\Users\koushik\OneDrive\Desktop\Nodejs\node-mongo\node_modules\mongodb-core\lib\connection\connection.js:309:10)
    at Socket.<anonymous> (C:\Users\koushik\OneDrive\Desktop\Nodejs\node-mongo\node_modules\mongodb-core\lib\connection\connection.js:452:17)
    at Socket.emit (node:events:527:28)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at Socket.Readable.push (node:internal/streams/readable:228:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
  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'
}

Please Help Me with this Problem and Please Mention The Solution. What Should I do To perform the operation as it is not working and op_query is deprecated in latest version.

CodePudding user response:

The error says what you need to do (ie use latest mongo node driver). Latest servers stopped supporting legacy OP_INSERT/OP_QUERY wire protocols

  • Related