Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialization error: MongoError: a collection already exists #175

Closed
octo-kumo opened this issue Aug 3, 2020 · 9 comments
Closed

Initialization error: MongoError: a collection already exists #175

octo-kumo opened this issue Aug 3, 2020 · 9 comments

Comments

@octo-kumo
Copy link

I am using the following constructor

new winston.transports.MongoDB({
    name: "http",
    db: process.env.MONGODB_URL,
    options: {
        poolSize: 2, useNewUrlParser: true,
        useUnifiedTopology: true
    },
    tryReconnect: true,
    collection: 'http',
    level: 'info'
})

It runs without issue for the first time, but whenever I run the code again, it gives me this error

winston-mongodb, initialization error:  MongoError: a collection 'database.http' already exists
    at MessageStream.messageHandler (/.../node_modules/mongodb/lib/cmap/connection.js:266:20)
    at MessageStream.emit (events.js:314:20)
    at processIncomingData (/.../node_modules/mongodb/lib/cmap/message_stream.js:144:12)
    at MessageStream._write (/.../node_modules/mongodb/lib/cmap/message_stream.js:42:5)
    at writeOrBuffer (_stream_writable.js:352:12)
    at MessageStream.Writable.write (_stream_writable.js:303:10)
    at TLSSocket.ondata (_stream_readable.js:714:22)
    at TLSSocket.emit (events.js:314:20)
    at addChunk (_stream_readable.js:304:12)
    at readableAddChunk (_stream_readable.js:280:9) {
  operationTime: Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1596430109 },
  ok: 0,
  code: 48,
  codeName: 'NamespaceExists',
  '$clusterTime': {
    clusterTime: Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1596430109 },
    signature: { hash: [Binary], keyId: [Long] }
  }
}
@Swagtex
Copy link

Swagtex commented Aug 3, 2020

@misuti
My current "fix": npm install mongodb@3.3.3

@a1300
Copy link

a1300 commented Aug 4, 2020

Thank you very much @Swagtex 👍
This worked for me!

@BNHDev
Copy link

BNHDev commented Aug 5, 2020

@Swagtex Thank you for your solution 👍👍👍

@keyyuki
Copy link

keyyuki commented Aug 6, 2020

I have same issue and solution of @Swagtex not work for me T_T

@backflip
Copy link

This seems to be related to Changes in behavior of Db.prototype.createCollection in mongodb@3.6.0 (see PR). So everything before 3.6.0 should work.

@backflip
Copy link

Possible fix: #176

@ceopaludetto
Copy link

ceopaludetto commented Aug 19, 2020

If you use various versions of mongodb in your codebase(such as mongoose), another solution is resolutions field in package.json, add:

"resolutions": {
    "mongoose/**/mongodb": "3.3.3"
},

Then reinstall packages running yarn

@yurijmikhalevich
Copy link
Member

Fixed in winston-mongodb@5.0.3.

@BasitMaqsood
Copy link

@misuti
My current "fix": npm install mongodb@3.3.3

Helpful, Thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants