Last active
September 23, 2019 19:06
-
-
Save hc3/f041961e3f92291f85dae71a181ea5a7 to your computer and use it in GitHub Desktop.
consulta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const value = await sellModel.aggregate([ | |
{ | |
$match: { | |
$and: [ | |
{ 'status': { $in: [0, 8] } }, | |
{ 'oc': { $in: ['001', '002', '004'] } }, | |
//{'seller':seller_code} | |
] | |
} | |
}, | |
{ | |
$group: { | |
_id: '$seller', | |
fat: { | |
$sum: '$sell_value' | |
}, | |
totalCoverage: { | |
$addToSet: '$client' | |
}, | |
schinCoverage: { | |
$addToSet: { | |
'client':'$client', | |
'produto': '902411' | |
} | |
} | |
} | |
}, | |
{ | |
$project: { | |
_id:0, | |
vendedor:"$_id", | |
valor_faturamento:"$fat", | |
cobertura_total:"$totalCoverage", | |
cobertura_schin:"$schinCoverage" | |
} | |
} | |
]).exec() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
deveria retornar algo assim:
tipo um array com vários vendedores e seus indicadores, oq eu não to conseguindo é calcular a cobertura do produto como na linha 20, nessa linha eu quero calcular quando clientes distintos compraram um ou mais produtos.
quem puder me dar uma luz de como resolver isso seria de grande ajuda.