Comments (10)
What do you mean? Using this library outside of a Laravel project?
from laravel-mongodb.
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).
from laravel-mongodb.
You should be able to just use the query builder, like you would in Laravel: https://github.com/jenssegers/Laravel-MongoDB#query-builder
from laravel-mongodb.
That works indeed, but I need to get the MongoClient and MongoDB objects.
from laravel-mongodb.
At least the MongoDB. This I couldn't succeed outside of a Jenssegers\Mongodb\Model extended class..
from laravel-mongodb.
DB::getMongoDB()
should work in that case.
https://github.com/jenssegers/Laravel-MongoDB/blob/master/tests/ConnectionTest.php#L27
from laravel-mongodb.
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.
from laravel-mongodb.
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.
from laravel-mongodb.
I developped my own connection class based on yours, now everything is fine.
Thank you!
from laravel-mongodb.
Hi , I have the same issue so could you please tell me what is your solution ?
Thank you :)
from laravel-mongodb.
Related Issues (20)
- Need to support upsert function in Laravel 10 HOT 1
- datetime casts not considering timezone HOT 2
- Transaction already in progress HOT 7
- Connection string is missing the option to create dsn as a SRV dsn HOT 3
- First argument of MongoDB\Laravel\Query\Builder::where must be a field path as "string". Got "null" HOT 6
- seperate read, write connection not working HOT 1
- castAttribute does not handle nullable immutable date times
- DatabaseTransactions and mongodb
- [Feature Request] Cast createdAt and updatedAt field by default,that is save by mongoose HOT 2
- hasMany or hasOne doesnt work without getIdAttribute HOT 11
- Array of ObjectId not being casted to string when retrieving data HOT 1
- `whereAny` and `whereAll` query Error HOT 4
- Apply casts when serializing embedded relations HOT 3
- Laravel 11 Support? HOT 2
- NOTIFIABLE NOT WORKING, Cannot access offset of type MongoDB\BSON\ObjectId in isset or empty in HOT 1
- MorphTo relation won't work when eager load if target model has different primary key HOT 1
- [BUG] hasMany and hasOne relation not working with ObjectId HOT 2
- toSql() Alias from toMql() HOT 4
- [Feature Request] Add enum collection cast HOT 1
- MongoDB\Driver\Exception\BulkWriteException: not primary in /app/vendor/mongodb/mongodb/src/Operation/Update.php:209 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-mongodb.