I am using jenssegers package in Laravel 5 for mongodb. I am inserting multiple data in below described way and data is inserted successfully in mongodb but then it through error before the script completes.
$AllTrans=array();
$AllTrans[]=array("InvoiceID"=>1,"Amount"=>50);
$AllTrans[]=array("InvoiceID"=>2,"Amount"=>150);
$mongo_connnection->collection('invoices')->insert($AllTrans);
Here is the error:
MongoException in Collection.php line 42:
No write ops were included in the batch
But i can not figure out problem, I have tried passing option like array('multi' => true) with insert query but it was not working.
It will work great with bulk addition, this way, you just need to create on array and pass it to it.
$temp = [
[
'item'=> "envelopes"
],
[
'item'=> "envelopesas"
],
[
'item'=> "lala"
]
];
$userData = DB::table('log')->raw( function ( $collection ) use ($temp) {
return $collection->insertMany($temp);
});