Is renameCollection() command when dropTarget=true an atomic operation?

According to doc: If true , mongod will drop the target of renameCollection prior to renaming the collection.
Want to understand if this operation is atomic or not. Or is it possible it may end up dropping the collection and then the command fails to rename the collection?

Hello @Ashish_Jha2, and welcome to the Developer Community Forums!

Regarding your question, as noted within our documentation, since MongoDB version 4.2 , when performing db.collection.renameCollection() , the operation obtains an exclusive lock on the source and target collections for the duration of the operation. All subsequent operations on the collections must wait until renameCollection() completes. Seeing as this operation has an intent exclusive lock on both collection, I believe that the rename would occur prior to releasing the lock, therefore, making this an atomic operation. However, an important note to this is the renaming a collection with dropTarget : true is atomic so long as the renamed collection stays within the same database .