I’m creating a website with nodejs+mongoose+mongodb. I’m looking for a good way to initialize the mongodb with some prepared data.
At present, I’m doing following in beforeEach:
- drop the database
- write some code to insert some data into the database
But I found this operation is not quick enough, it takes nearly 1s.
I wonder is there any better and quicker way to prepared testing data.
You can drop all collections without droping db that will not remove file and not reallocate 192 mb of space on disk.
pseudo code
in mongodb shell you can do db[‘foo’] for foo collection name. I don’t know if mongoose supports this same way.