Coder Social home page Coder Social logo

Comments (10)

jenssegers avatar jenssegers commented on June 3, 2024

What do you mean? Using this library outside of a Laravel project?

from laravel-mongodb.

nbertal avatar nbertal commented on June 3, 2024

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.

jenssegers avatar jenssegers commented on June 3, 2024

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.

nbertal avatar nbertal commented on June 3, 2024

That works indeed, but I need to get the MongoClient and MongoDB objects.

from laravel-mongodb.

nbertal avatar nbertal commented on June 3, 2024

At least the MongoDB. This I couldn't succeed outside of a Jenssegers\Mongodb\Model extended class..

from laravel-mongodb.

jenssegers avatar jenssegers commented on June 3, 2024

DB::getMongoDB() should work in that case.

https://github.com/jenssegers/Laravel-MongoDB/blob/master/tests/ConnectionTest.php#L27

from laravel-mongodb.

nbertal avatar nbertal commented on June 3, 2024

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.

nbertal avatar nbertal commented on June 3, 2024

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.

nbertal avatar nbertal commented on June 3, 2024

I developped my own connection class based on yours, now everything is fine.

Thank you!

from laravel-mongodb.

waelwalid avatar waelwalid commented on June 3, 2024

@nbertal

Hi , I have the same issue so could you please tell me what is your solution ?
Thank you :)

from laravel-mongodb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.