I'm using a real Mongo instance for my integration tests. On every test, I call mongorestore my_db_state --drop because I need a clean db to start the next test.

On my tiny db (with only one test user account) it takes 180 ms to run mongorestore my_db_state (without --drop) and 455 ms with --drop.

I don't understand why it's taking so long to drop the db, but how can I speed this up?

I may have a bunch of different connections on the mongo server because I never close them on my Flask server, but they probably should be closed after the test is over...just not sure if this is an issue to care about.

Is there a faster way to restore a snapshot to its original state for testing purposes?

New contributor
libby is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • Does mongorestore on its own not properly restore the database to its proper state? I don't see why you need to drop the database just to recreate unless you don't have confidence that mongorestore is working properly. – corsiKa Nov 20 at 4:03
  • Unfortunately, no it doesn't. It won't overwrite documents with matching _ids, it will only insert atop what's already there. – libby Nov 20 at 6:17
  • 1
    Very interesting - I wonder if that's intentional or not. While this is certainly on topic as an SQA problem, I wonder if it isn't worth asking the question on dba.stackexchange as well, from a different perspective. This is about speeding up your tests - any option to speed up your tests works for you. But you could ask the dba folks about how to reset the database faster than --drop - perfectly allowable since they approach from different perspectives! – corsiKa Nov 20 at 6:23
  • @corsiKa thanks will do – libby Nov 20 at 7:27

Your Answer

libby is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.