Skip to content

exclude System Collections in listCollectionNames() #3320

Closed
@masterbater

Description

@masterbater

MongoDB stores system information in collections that use the .system.* namespace, which MongoDB reserves for internal use. Do not create collections that begin with system.

https://www.mongodb.com/docs/manual/reference/system-collections/

.system.profile
.system.js
.system.views

Is your feature request related to a problem?

system.views is a systems collection but in laravel includes it in the result which causes issue with testing traits that drops all tables

Other system collection that could in the testing database
.system.profile
.system.js

Describe the solution you'd like

Exclude it when dropping all tables, like using migrate:fresh, testing traits like RefreshDatabase, DatabaseMigration

Additional context

Image

Temporary solution add a custom command, but I strongly think that system collections should be excluded in listCollectionNames

$database = DB::connection('mongodb')->getMongoDB();

    foreach ($database->listCollectionNames() as $collectionName) {

        if (in_array($collectionName, ['system.views', 'system.profile'])) {
            continue;
        }
        DB::table($collectionName)->delete();
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions