I have records of this form:
{
    "_id" : ObjectId("57993e64498e9bebb535154f"),
    "fooKey" : "123|a|b|c|||d",
    "locationId" : 1,
    "type" : "FOO"
}
{
    "_id" : ObjectId("579e0a3d498e9bebb545ff96"),
    "fooKey" : "123|x|y|z|||v",
    "locationId" : 1,
    "type" : "FOO"
}
{
    "_id" : ObjectId("57a5443b498e381a40a26afb"),
    "fooKey" : "123|a|b|c|||d",
    "locationId" : 2,
    "type" : "FOO"
}
{
    "_id" : ObjectId("57a63fef498e381a40a60347"),
    "fooKey" : "123|x|y|z|||v",
    "locationId" : 2,
    "type" : "FOO"
}
{
    "_id" : ObjectId("579ab3ce498e9538125052ca"),
    "fooKey" : "456|h|j|j|||k",
    "locationId" : 2,
    "type" : "BAR"
}
I went through the documentation and this seems like it could be complex given that I need this today (and I am not an expert in Mongo). What I need an aggregation query (for only records with "type" : "FOO") to return groups grouped by:
- The first field in the pipe-delimited string in the "fooKey" field (for example "123"
 - The locationId
 
and then where the resulting count of the type field (where it is specifically equal to "FOO" is greater than 1.
That is given the records above I need something along the lines of records 1 and 2 returned in a group along with records 3 and 4 aggregated in a group... along with a count of the group size.
Expected Output
Something like this:
{ 
    "foo": "123", 
    "locationId": 1, 
    "type": "FOO", 
    "total": 2 
}, 
{ 
    "foo": "123", 
    "locationId": 2,
    "type": "FOO", 
    "total": 2 
}