Does dropDatabase() require any special considerations like the equivalent SQL operation takes?

Hi, there.

I’m new to MongoDB and am running version 8.0 community edition.

In a Postgresql SQL context, dropping a DB (e.g. the foo DB) might use the following steps:

  1. Prevent any new connections: UPDATE pg_database SET datallowconn = ‘false’ WHERE datname = foo
  2. Drop any existing connections: SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = foo
  3. Drop the database: DROP DATABASE foo

If I’m looking at the MongoDB documentation correctly, it says that to drop a DB, you just need to run dropDatabase:

Does MongoDB require any consideration for the 1st two steps? I know that I can accomplish step 1 with this:

db.runCommand({
  revokeRolesFromUser: "username",
  roles: [{ role: "readWrite", db: "foo" }]
});

But, my efforts to use killOp, killAllSessions for step 2 haven’t been successful. I did read a post on the MongoDB forums that illustrated that if the existing write operations/clients were not canned, then the database wouldn’t be dropped properly.

Thx for any help!

Rodney

After researching this further, I’ve come to the conclusion that using dropDatabase() by itself is all that is needed. But, I’ll give this to ChatGBT for the win:

So, I will probably, as an added safeguard, revoke some rights to the users of the DB, but I’m not worried anymore about data corruption or other issues.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.