How to implement MongoDB query in Laravel 5? -
i created mongodb query have use in laravel controller.
my query
db.pms.aggregate([ { $match: { "panelid": "a00898" } }, { $project: { eventts: 1, mainspower: 1, } }, { $unwind: { path: "$mainspower", includearrayindex: "arrayindex", preservenullandemptyarrays: true } }, { $project: { mainspower: 1, timestamp: { "$add": [ "$eventts", { "$multiply": [ 60000, "$arrayindex" ] } ] } } } ]);
i tried use query in laravel function little confused. please me how implement query in laravel.
perform raw expressions on internal mongocollection object run aggregation:
$result = db => collection('pms')->raw(function ($collection){ return $collection->aggregate(array( array( '$match' => array( "panelid" => "a00898" ) ), array( '$project' => array( 'eventts' => 1, 'mainspower' => 1 ) ), array( '$unwind' => array( 'path' => "$mainspower", 'includearrayindex' => "arrayindex", 'preservenullandemptyarrays' => true ) ), array( '$project' => array( '_id' => 0, 'mainspower' => 1, 'timestamp' => array( "$add" => array( "$eventts", array( "$multiply" => array( 60000, "$arrayindex" ) ) ) ) ) ) )); });
Comments
Post a Comment