Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Mongo not as Main Database cannot drop collection #1241

Closed
yukopangestu opened this issue Jul 14, 2017 · 3 comments
Closed

Using Mongo not as Main Database cannot drop collection #1241

yukopangestu opened this issue Jul 14, 2017 · 3 comments
Labels

Comments

@yukopangestu
Copy link

Hi, please help me,

I obviously love mongo db especially they can be handled by PHP, but for my current project I use both MySQL and Mongo as database, but MySQL is my main database in my database.php configuration however I use these code to connect and make collection:

Schema::connection('mongodb')->create('message', function($collection){ $collection->index('id'); $collection->string('message'); $collection->integer('from'); $collection->integer('to'); });

however when the function down in migration file I wrote this:

Schema::connection('mongodb')->dropIfExists('message');

But the collection didn't drop, what's wrong with my code?

@ghost
Copy link

ghost commented Aug 19, 2017

Schema::connection('mongodb')->drop('mycollection');

Check Jenssegers\Mongodb\Schema\Blueprint for supported methods.

@KaylaLamp
Copy link

KaylaLamp commented Oct 29, 2018

I know this is late, but I am running into this issue as well.

When I run migrate:fresh with my migration organised as the above, the error log says

a collection 'example.drivers' already exists

When I move Schema::connection('mongodb')->drop('drivers') into the up() function of the migration file, the collection is dropped and all works correctly. The down function is being reached, but it is almost as if the statement inside it is being ignored.

@nigandres
Copy link

Only to add information at the comment of KaylaLamp the method If exists would be helpful if you do not have something alredy created.
Schema::connection('mongodb')->dropIfExists('collection');

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

No branches or pull requests

4 participants