-
Type:
Bug
-
Resolution: Done
-
Priority:
Major - P3
-
None
-
Affects Version/s: 3.6.0
-
Component/s: None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Before 3.6.0 using db.createCollection("name") silently returns the collection if it already exists. Now we get [simply run the start script from package.json twice]:
(node:26027) UnhandledPromiseRejectionWarning: MongoError: a collection 'bad-node-mongodb-3-6-0.tester' already exists
at MessageStream.messageHandler (.../bad-mongo/node_modules/mongodb/lib/cmap/connection.js:266:20)
at MessageStream.emit (events.js:315:20)
at processIncomingData (.../bad-mongo/node_modules/mongodb/lib/cmap/message_stream.js:144:12)
at MessageStream._write (.../bad-mongo/node_modules/mongodb/lib/cmap/message_stream.js:42:5)
at doWrite (_stream_writable.js:403:12)
at writeOrBuffer (_stream_writable.js:387:5)
at MessageStream.Writable.write (_stream_writable.js:318:11)
at Socket.ondata (_stream_readable.js:717:22)
at Socket.emit (events.js:315:20)
at addChunk (_stream_readable.js:295:12)
Repro:
const { MongoClient } = require("mongodb") const database = "mongodb://localhost:27017/bad-node-mongodb-3-6-0" async function startup() { const connection = await MongoClient.connect(database, { useUnifiedTopology: true }) const db = connection.db() await db.createCollection("tester") console.log("all done") } startup()
{ "name": "bad-mongo", "version": "1.0.0", "main": "index.js", "license": "MIT", "scripts": { "start": "node index.js" }, "dependencies": { "mongodb": "^3.6.0" }}
I found no hint in the release notes on a potential breaking change. So I guess it's related to https://jira.mongodb.org/browse/NODE-2537.
I'm using Node.js 12.18.1 with MongoDb 4.2.8 on Ubuntu 20.04.1.