I am not able to delete collection from admin db which i made it by mistake in sharded cluster

db.test.drop()
MongoServerError: Cannot drop collection in 'admin' database in sharded cluster
    at Connection.onMessage (/Applications/MongoDB Compass.app/Contents/Resources/app.asar.unpacked/node_modules/@mongosh/node-runtime-worker-thread/dist/worker-runtime.js:2:962566)
    at MessageStream.<anonymous> (/Applications/MongoDB Compass.app/Contents/Resources/app.asar.unpacked/node_modules/@mongosh/node-runtime-worker-thread/dist/worker-runtime.js:2:960452)
    at MessageStream.emit (node:events:513:28)
    at p (/Applications/MongoDB Compass.app/Contents/Resources/app.asar.unpacked/node_modules/@mongosh/node-runtime-worker-thread/dist/worker-runtime.js:2:986660)
    at MessageStream._write (/Applications/MongoDB Compass.app/Contents/Resources/app.asar.unpacked/node_modules/@mongosh/node-runtime-worker-thread/dist/worker-runtime.js:2:985281)
    at writeOrBuffer (node:internal/streams/writable:392:12)
    at _write (node:internal/streams/writable:333:10)
    at Writable.write (node:internal/streams/writable:337:10)
    at Socket.ondata (node:internal/streams/readable:766:22)
    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)

i am getting this error

Hi @Deepanshu_Kumar and welcome to the community!
I’ve find that from the documentation:

“Starting in MongoDB 5.0, the drop command and the
db.collection.drop()
method return an error if you try to drop a collection in the admin database or the config database from a mongos. To drop these collections, connect to the config server and run the command there.”
https://www.mongodb.com/docs/manual/reference/method/db.collection.drop/#:~:text=Starting%20in%20MongoDB%205.0,run%20the%20command%20there.

Regards

2 Likes

Hi @Fabio_Ramohitaj how to connect with config server ?

Hi @Ayushi_Nanda and welcome to the Community!
Simply point to the nodes that contain the config server.
How to set the connection string:

Regards