Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

metricsflow's avatar

Integrating 3rd Party MongoDB Models with Spark

I'm currently using a third party package to allow Laravel to use MongoDB as its database (https://github.com/jenssegers/laravel-mongodb) This required modifying the inheritance of many classes from the default Illuminate\Database\Eloquent\Model class to Jenssegers\Mongodb\Eloquent\Model. All of my models are extending this new class and the database is functional. I've seeded the database and can successfully query the models through php artisan tinker commands.

My problem now is that when I attempt to log in to my web app as a dummy user I seeded, Spark takes my model class that extends the Jenssegers\Mongodb\Eloquent\Model class and treats it as an Illuminate\Database\Eloquent\Model object. This ends up using an Illuminate\Database\Query\Builder object which causes the query to fail because it's attempting to use SQL. Is there something about Spark that is overriding my models to treat them as Illuminate\Database\Eloquent\Model objects? Is this something that can be configured? I can't seem to figure out why the object is changing classes.

0 likes
1 reply
orrd's avatar

You would run into all sorts of issues if you try to use Spark with MongoDB. Spark just isn't designed for a no-SQL database, and laravel-mongodb requires its own extended version of Eloquent (as you discovered). So that's not going to work.

Why not let Spark use MySQL for its tables, and then just use MongoDB for your own tables where it makes sense to use it? (Set protected $connection = 'mongodb'; on those models.)

Please or to participate in this conversation.