Skip to content

Instantly share code, notes, and snippets.

@hc3
Last active September 23, 2019 19:06
Show Gist options
  • Save hc3/f041961e3f92291f85dae71a181ea5a7 to your computer and use it in GitHub Desktop.
Save hc3/f041961e3f92291f85dae71a181ea5a7 to your computer and use it in GitHub Desktop.
consulta
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()
@hc3
Copy link
Author

hc3 commented Sep 23, 2019

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.

{
	vendedor:'102',
	cobertura_schin_total:array(50),
	cobertrua_total:array(150),
	valor_faturamento:33940.78
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment