Skip to content

Truncate is the fastest to use for testing #3268

Answered by GromNaN
masterbater asked this question in General
Discussion options

You must be logged in to vote

You don't need to know about the models, you can list all the collections of your database and delete all the documents they contain.

$database = DB::connection('mongodb')->getMongoDB();
foreach($database->listCollectionNames() as $collectionName) {
    $database->getCollection($collectionName)->deleteMany([]);
}

Don't drop the collections if you use indexes or specific collections options like timeseries.

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
4 replies
@masterbater
Comment options

@GromNaN
Comment options

Answer selected by masterbater
@masterbater
Comment options

@masterbater
Comment options

Comment options

You must be logged in to vote
2 replies
@masterbater
Comment options

@masterbater
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants