Crud: Support for MongoDB

Created on 24 Jul 2017  路  10Comments  路  Source: Laravel-Backpack/CRUD

Hi!

I like MongoDB and it's a shame that it's not supported, so I'm working on it.

I currently have a question, in the function "setFromDB", Backpack gets the type of column to generate the tables, but in Mongo how could it do? Since that does not exist in Mongo.

There should then be a "migration" emerge, right?

public function getColumnType($table, $column) { $table = $this->connection->getTablePrefix().$table; return $this->connection->getDoctrineColumn($table, $column)->getType()->getName(); }

Sorry for my bad English!

Most helpful comment

Yes, confirmed, I currently use it in a project in production! :)

Thanks

All 10 comments

Hi @dboscanv ,

I'd also love to support MongoDB, but I'm not too familiar with it, so can't promise it's coming any time soon. A lot of work to maintain Backpack as-is.

I would recommend not using setFromDb() at all - I never do. I find it cleaner to manually define each column and field, and that part should work on MongoDB too, since it's just Eloquent, no SQL.

Hope it helps.
Cheers!

Quick update: it has been reported that Backpack works well with MongoDB, using this excellent package: https://github.com/jenssegers/laravel-mongodb

Yes, confirmed, I currently use it in a project in production! :)

Thanks

@dboscanv could you please explain how you got Backpack to be compatible with MongoDb?

I'm also using https://github.com/jenssegers/laravel-mongodb

I created a new crud model and then inside the generated model I replaced

use Illuminate\Database\Eloquent\Model;
use Backpack\CRUD\CrudTrait;

class Tag extends Model
{

by

use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
use Backpack\CRUD\CrudTrait;

class Tag extends Eloquent

and then replaced

protected $table = 'tags';

by

    protected $connection = 'mongodb';
    protected $collection = 'Tags';

That should be all I have to do I think?

But now I'm getting this error:

call_user_func_array() expects parameter 1 to be a valid callback, class 'MongoDB\Database' does not have a method 'getDoctrineDriver'

How did you get it to work? Thanks that would be really helpful

@tabacitu I realize you don't want to support this officially.. but since it apparently already does work with little effort.. it would be nice if you could document the steps needed in order to make it work. Thanks!

I managed to get it to work. I needed to edit two vendor files so far.. here is my commit with the modifications

https://github.com/vesper8/CRUD/commit/563df72036e037189c7690d022bff715942eb376

@tabacitu would you be willing to accept a PR to add these in? They are super minor changes and they won't affect anyone else but will make it easier to use with https://github.com/jenssegers/laravel-mongodb for other MongoDB users

I would hate to have to use my fork going forward as I want to stay up-to-date with your latest changes

As for the CrudController, I had to comment out the setFromDB method and define my own columns

Update: Thanks A LOT for the PR @vesper8 ! Merged it, you and others should be able to use MongoDB with Backpack 3.6.6+

Cheers!

@tabacitu Thank you, I am used mongo via jenssegers/mongodb.
Would you tell me it if support the both addField method with parameter['type' => 'select'] and PermissionManager

@coljiang I don't understand. Could you please rephrase?

@vesper8 thank you for helping this awesome package to support mongodb!

@tabacitu i also submitted a PR to support mongodb further, the changes are minor and won't affect anyone else as well https://github.com/Laravel-Backpack/CRUD/pull/1891

i applied some change to setFromDB to get columns from fillable if using mongodb

would you be willing to accept this PR so the others can use laravel backpack and mongodb without any difficulties?

thanks!

Merged! Thanks again @andrycs .

Was this page helpful?
0 / 5 - 0 ratings