-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 the connection everywhere #58
Comments
What do you mean? Using this library outside of a Laravel project? |
Nope, for instance I want to use it in a class that is not a "Model" per say (but inside a L4 project where jenssegers/Laravel-MongoDB is present and configured). |
You should be able to just use the query builder, like you would in Laravel: https://github.com/jenssegers/Laravel-MongoDB#query-builder |
That works indeed, but I need to get the MongoClient and MongoDB objects. |
At least the MongoDB. This I couldn't succeed outside of a Jenssegers\Mongodb\Model extended class.. |
https://github.com/jenssegers/Laravel-MongoDB/blob/master/tests/ConnectionTest.php#L27 |
I suspect it doesn't work because it does not precise what connection to use, so it's using the default one (ie. in my case I use postgre): call_user_func_array() expects parameter 1 to be a valid callback, class 'Illuminate\Database\PostgresConnection' does not have a method 'getMongoDB' So I thought I was a dependency issue, but I couldn't resolve it. |
Just to be clear and summarizing a little: It seems impossible to access the MongoClient or MongoDB objects when not working with established Models if Mongo not the default DB connection. |
I developped my own connection class based on yours, now everything is fine. Thank you! |
Hi , I have the same issue so could you please tell me what is your solution ? |
Hi again,
I would like to use the MongoDB connection outside of a Model (ie. a custom class not dependant of a specific collection).
So far:
DB::getMongoDB() does'nt work (dependency issue, couldn't resolve)
DB::connection('mongodb') returns NULL
What is the best practice?
A) still use your IoC ? Then how can I proceed?
B) Open the connection using the original Mongo PHP library, everytime I need it ? Isn't it efficient because it might trigger multiple connections instead of a single instance?
Thanks in advance!
The text was updated successfully, but these errors were encountered: