Home > Software engineering >  MongoServerError: cannot create a new collection already using 500 collections of 500, error code: 8
MongoServerError: cannot create a new collection already using 500 collections of 500, error code: 8

Time:06-27

I am trying to insertOne more document in a new collection using this code:

await client.db(db).collection(newCollection).insertOne(newDocument);

However, this runs into error code 8000, which is not documented here: https://github.com/mongodb/mongo/blob/master/src/mongo/base/error_codes.yml .

MongoServerError: cannot create a new collection -- already using 500 collections of 500
    at Connection.onMessage (/home/pi/projects/myProject/node_modules/mongodb/lib/cmap/connection.js:210:30)
    at MessageStream.<anonymous> (/home/pi/projects/myProject/node_modules/mongodb/lib/cmap/connection.js:63:60)
    at MessageStream.emit (node:events:527:28)
    at processIncomingData (/home/pi/projects/myProject/node_modules/mongodb/lib/cmap/message_stream.js:132:20)
    at MessageStream._write (/home/pi/projects/myProject/node_modules/mongodb/lib/cmap/message_stream.js:33:9)
    at writeOrBuffer (node:internal/streams/writable:390:12)
    at _write (node:internal/streams/writable:331:10)
    at Writable.write (node:internal/streams/writable:335:10)
    at TLSSocket.ondata (node:internal/streams/readable:766:22)
    at TLSSocket.emit (node:events:527:28) {
  ok: 0,
  code: 8000,
  codeName: 'AtlasError',
  [Symbol(errorLabels)]: Set(0) {}
}

I did further research and found that number of collections one create is not limited by the user ("In general, try to limit your replica set to 10,000 collections") as stated here: https://www.mongodb.com/developer/products/mongodb/schema-design-anti-pattern-massive-number-collections/#:~:text=In general, try to limit your replica set to 10,000 collections.

I am using Atlas on a shared cluster. Is this an Atlas issue or an issue with my code?

CodePudding user response:

yes, it's atlas M0 free restriction. See Database and Collections here

  • Related