使用基于关键AND值的PHP和MongoDB排序结果?

For my case i am using MongoDB to store a whole bunch of products from 50 countries, entry in DB looks something like this:

{
    _id: xxxxxxxxxxxxxxx,
    country: 'au',
    title: 'Equipment X',
    price: 1000,
},
{
    _id: xxxxxxxxxxxxxxy,
    country: 'us',
    title: 'Equipment Y',
    price: 1000,
},
...
...

I would like to know if it is at all possible to query all products and sort by country from au FIRST, then the rest of the products after that. The simple MongoDB sort seems to only sort by key. If it is possible, does it involve map/reduce?

Edit: A more detailed example

Documents in collection:

{ country:'cn', title:'Equipment A', price:'100'},
{ country:'au', title:'Equipment B', price:'100'},
{ country:'za', title:'Equipment C', price:'100'},
{ country:'us', title:'Equipment D', price:'100'},
{ country:'nz', title:'Equipment E', price:'100'},
{ country:'it', title:'Equipment F', price:'100'},
{ country:'nz', title:'Equipment G', price:'100'},
{ country:'au', title:'Equipment H', price:'100'},

I am looking for a sort that will return products from nz to be at the top and then follow by all other products, like this:

{ country:'nz', title:'Equipment E', price:'100'},
{ country:'nz', title:'Equipment G', price:'100'},
{ country:'au', title:'Equipment B', price:'100'},
{ country:'au', title:'Equipment H', price:'100'},
{ country:'cn', title:'Equipment A', price:'100'},
{ country:'it', title:'Equipment F', price:'100'},
{ country:'us', title:'Equipment D', price:'100'},
{ country:'za', title:'Equipment C', price:'100'},

By sorting on a key, it means sorting on the values in a key. This is what you want, I think. (Left off the beginning part to connect to the db and pick a collection).

$cursor = $collection->find();
$cursor->sort(array('country' => 1))

update So is this what you want to do?

$cursor = $collection->find(array('country' => 'nz'));
// process your nz products...

$cursor = $collection->find(array('country' => array( '$neq' => 'nz' )));
// process the rest of your products...

update2 Well, I think you may need to resort to doing something like this, if you really need this functionality.

// create a new field on the records that don't have it yet
$collection->update(
   array('country' => 'nz', array('first' => array('$exists' => false))), 
   array('$set' => array('first'=>1)), 
   array('multiple' => true));
// ensure index on that field
$collection->ensureIndex(array('first' => 1));
// find everything
$cursor = $collection->find();
// sort on that field
$cursor->sort(array('first':-1));

The simple MongoDB sort seems to only sort by key

Truly uninformed nonsense.

MongoDB can sort by multiple criteria. A simple look at the basic sorting documentation would have been useful here.

http://www.mongodb.org/display/DOCS/Sorting+and+Natural+Order