Calling Mongodb stored functions on an insert in php -
i'm using mongodb 3.2 php in laravel jensseger laravel-mongodb, documentation here: https://github.com/jenssegers/laravel-mongodb
i'm inserting data through code , works fine:
$clientes = db::connection(env('db_database'))->collection('catalogo_clientes'); $clientes->insert(array("_id" => "1", "nombre" => "test", "disponible" => 1));
however, i'd use function created in mongo instead of "1" in "_id", when inserting through command line i'd use this, works fine:
db.loadserverscripts(); db.catalogo_clientes.insert( { _id: getnextid("clientes"), nombre: "bob x.", disponible: 1 } )
how can insert through php mongo using same function of "getnextid()"?
this example using jenssegers' lib:
$result = db::collection('your_collection')->raw(function($collection) use ($folio, $name, $type, $entrega_digital, $motivo_rechazado) { return $collection->updateone( array('folio' => (int)$folio, 'documentos_'.$type.'.nombre' => $name), array( '$set' => array('documentos_'.$type.'.$.entrega_digital' => $entrega_digital, 'documentos_'.$type.'.$.motivo_rechazado' => $motivo_rechazado) ) ); });
with cursor can use native methods: https://docs.mongodb.com/manual/
Comments
Post a Comment