How to delete all Mongodb Collections in Laravel

Asked

Viewed 89 times

3

A good practice in TDD is to keep the database clean between tests. For this, Laravel uses the Trait RefreshDatabase. However, this still doesn’t work for the Mongodb database.

My idea is to delete all Collections in the method tearDown of my test class.

How to Delete All Stories?

I use the implementation https://github.com/jenssegers/laravel-mongodb

1 answer

2


One option is to delete the database on tearDown, using even Mongo commands, for example

DB::command(['dropDatabase' => 1]);

It is possible to put this in a trait, similar to the RefreshDatabases

Or else:

There is an open Issue on this, in the repository of Laravel-mongdb, can help:

https://github.com/jenssegers/laravel-mongodb/issues/1475

Browser other questions tagged

You are not signed in. Login or sign up in order to post.