Laravel-mongodb: How to change a field name / running a raw query?

Created on 27 Sep 2016  路  2Comments  路  Source: jenssegers/laravel-mongodb

I'd like to run this from my application:

db.values.updateMany( { entity_id: 123 }, { $rename: { "oldname": "newname" } } )

I've tried multiple functions like raw() and a direct statement with statement() on the connection \DB::connection('mongodb') but everything is producing errors like Call to a member function prepare() on null.

How can I run this?

Most helpful comment

Thank you @pi0! The working result:

\DB::connection('mongodb')->collection('values')->where('entity_id',123)->update([
    '$rename' => ['oldname' => 'newname']
]);

All 2 comments

You may use something like this to rename

        DB::connection('mongodb')->collection('values')->update([
            { entity_id: 123 },
            '$rename'=>['oldname'=> "newname"],
        ]);

See here for more details.

Thank you @pi0! The working result:

\DB::connection('mongodb')->collection('values')->where('entity_id',123)->update([
    '$rename' => ['oldname' => 'newname']
]);
Was this page helpful?
0 / 5 - 0 ratings

Related issues

YSimple picture YSimple  路  3Comments

sebastiaanluca picture sebastiaanluca  路  3Comments

pirmax picture pirmax  路  3Comments

phuocduy1988 picture phuocduy1988  路  3Comments

imrannazirbhat picture imrannazirbhat  路  3Comments