I have performed the following query:
db.Indiv2.aggregate(
{$unwind: '$conso'},
{$group: {_id: {conso:'$conso.nom_commercial', region:"$region"}, sum:
{$sum: 1}}},
{$sort : {sum : -1}},
{$group: {
_id: "$_id.region",
"conso": {
$first: "$_id.conso"
},
"sum": {
$first: "$sum"
},
}},
{$sort : {_id : 1}}
);
which returns the highest consumed food by region in the following format:
{
"_id" : {
"conso" : "x",
"region" : 1
},
"sum" : 73226.0
},
{
"_id" : {
"conso" : "x",
"region" : 8
},
"sum" : 25683.0
},
{
"_id" : {
"conso" : "grandlait demi �cr�m� uht",
"region" : 1
},
"sum" : 251.0
}
However, a lot of foods do not have names. Such items are named "x" (example above). I would like to filter my query to exclude such items. I am looking for an equivalent of a filter which can either filter strings which length are below 2 characters or filter the string "x".