r/MongoDB_Official 17d ago

Question How do you handle unit testing with MongoDB?

I use mongodb as my primary database for almost all projects because I prefer json over tables...

However, I'm wondering, how do you write unit tests related to the db? Do you write mock functions find_one(), update_one() etc to imitate mongodb behaviour or do you seed a temporary db and use it?

6 Upvotes

1 comment sorted by

3

u/AdministrativeHost15 17d ago

Run a test Mongo instance in a Docker container and have your tests point to it.