Ok i think i did this wrong.
This is my current collection however I need to order these by percentage.
array (
'_id' => new MongoId("505006de36314b4b27000001"),
'status' => 'pending',
'store_id' => new MongoId("505006de36314b4b27000000"),
'minspendone' => '50.00',
'cashbackone' => '1.50',
'percentageone'▼ => '0.03',
'minspendtwo' => '100.00',
'cashbacktwo' => '3.00',
'percentagetwo' => '0.03',
'minspendthree' => '',
'cashbackthree' => '',
'percentagethree' => '',
'minspendfour' => '',
'cashbackfour' => '',
'percentagefour' => '',
)
so would I better of changing it to the following
array (
'_id' => new MongoId("505006de36314b4b27000001"),
'status' => 'pending',
'store_id' => new MongoId("505006de36314b4b27000000"),
'offers' => array(
'minspend' => '50.00',
'cashback' => '1.50',
'percentage' => '0.03'),
array(
'minspend' => '100.00',
'cashback' => '3.00',
'percentage' => '0.03'))
)
could someone please advise me.
Russell,
If you wish to use the mongodb internal sort function you will need to split the array elements into separate documents.
Mongodb sort works to set the order of whole documents returned, rather the return order of elements within documents.
Hope that clarifies.