php - Sort sub array by total charges -


i want perform sorting total_charges. mongodb data following

 {     "_id" : objectid("534bceb303ea2ecd1de86944"),     "hotel" : [          {             "0" : 0,             "hotelid" : "123",             "name" : "hotel - demo1",             "city" : "paris",             "address1" : "demo -paris ",             "total_charges" : 1653.76,             "propertyavailable" : 1         },          {             "0" : 0,             "hotelid" : "134",             "name" : "hotel - demo2",             "city" : "paris",             "address1" : "demo paris ",             "total_charges" : 1875.71,             "propertyavailable" : 1         },          {             "0" : 0,             "hotelid" : "145",             "name" : "hotel - demo3",             "city" : "paris",                 "address1" : "demo paris ",             "total_charges" : 1143.18,             "propertyavailable" : 1         }     ],     "size" : 3 } 

i tried in php. find working sorting not working

        $dcnew = $dbnew->selectcollection($a);         $results = $dcnew->find()->sort(array("hotel.total_charges" => 1));         echo "<pre>";         foreach($results $test) {                $test1=$test;         }         echo "</pre>";     $smarty->assign("result",$test1['hotel']);     $smarty->assign('template',"mongo_hotel_search_listing.tpl"); 

any idea why not working?
thank you

following answer working question

db.collection.aggregate([{ "$unwind": "$hotel" },{ $sort : { 'hotel.total_charges' : 1 } },{$group:{_id:'$hotel.name',hotel:{$push:{'total_charges':'$hotel.total_charges'}}}}]) 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -