-1
I’m making a agreggation
in collect
pedidos
where at the end I make a group
to count how many pedidos
has every status.
So far, so good...
Only when I put it on match
looking for a status
specific it finds more data than when it is not set value of the status
in the match
;
[
{
'$match': {
'$and': [
{
'created_at': {
'$gte': new
Date(
'Wed, 01 May 2019 00:00:00 GMT'
),
'$lte': new
Date(
'Sat, 01 Jun 2019 00:00:00 GMT'
)
}
},
{
'status': 'ATIVO'
},
{
'$or': [
{
'deleted_at': null
},
{
'deleted_at': {
'$exists': false
}
}
]
}
]
}
},
{
'$sort': {
'created_at': -1
}
},
{
'$group': {
'_id': '$msisdn',
'order': {
'$last': '$$ROOT'
}
}
},
{
'$match': {
'order.status': 'ATIVO'
}
},
{
'$group': {
'_id': '$order.status',
'count': {
'$sum': 1
}
}
}
]
//output
_id:"ATIVO"
count: 3097
[
{
'$match': {
'$and': [
{
'created_at': {
'$gte': new
Date(
'Wed, 01 May 2019 00:00:00 GMT'
),
'$lte': new
Date(
'Sat, 01 Jun 2019 00:00:00 GMT'
)
}
},
{
'$or': [
{
'deleted_at': null
},
{
'deleted_at': {
'$exists': false
}
}
]
}
]
}
},
{
'$sort': {
'created_at': -1
}
},
{
'$group': {
'_id': '$msisdn',
'order': {
'$last': '$$ROOT'
}
}
},
{
'$group': {
'_id': '$order.status',
'count': {
'$sum': 1
}
}
}
]
// output
_id:"ATIVO"
count: 2737
You’re starting to realize why the relational model is still much better for most applications.
– Maniero
Capable, always thought that, but, there are situations that we do not have choices :P
– Andrew Rodrigues Brunoro