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'},