When following the code in the “CRUD Operations Using Mongoose: saving a document” part:
if I follow the course code and mongoose version, it gives me error:
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 D:\Javascript\mongo-demo\node_modules\mongodb-core\lib\connection\pool.js:595:61
at authenticateStragglers (D:\Javascript\mongo-demo\node_modules\mongodb-core\lib\connection\pool.js:513:16)
at Connection.messageHandler (D:\Javascript\mongo-demo\node_modules\mongodb-core\lib\connection\pool.js:549:5)
at emitMessageHandler (D:\Javascript\mongo-demo\node_modules\mongodb-core\lib\connection\connection.js:309:10)
at Socket.<anonymous> (D:\Javascript\mongo-demo\node_modules\mongodb-core\lib\connection\connection.js:452:17)
at Socket.emit (node:events:513:28)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)
at Readable.push (node:internal/streams/readable:234: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'
}
If I upgrade the driver to current, error message become
(node:6408) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
(Use `node --trace-deprecation ...` to show where the warning was created)
(node:6408) [MONGODB DRIVER] Warning: Current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
So I changed the code to mongoose.connect('mongodb://localhost:27017/playground', { useNewUrlParser: true, useUnifiedTopology: true })
Now it just doesn’t respond and eventually timeout.
What’s the problem here? Any help is appreciated!
My OS is Win10, vs code version 1.74.2, Node version 16.14.2
Back in VSCode, kill and re-run ‘node .\index.js’. I got more from my ‘result’ than Mosh does, but a check into MongoDB Compass and it shows my Document.