I have two functions, one is to find number of users, which works:
async function getAggregateSparkUserIdCount(userid) {
var promise = await new Promise(function (resolve, reject) {
FutureTasks.aggregate([
{
$match: {
"userid": {$eq: userid}
}
},
{
$group: {
_id: "$userid", count: {$sum: 1}
}
}
], (err, db) => {
err ? reject(err) : resolve(db);
});
});
return promise;
}
when there is no user this returns
[ ]
or when user sec123 appears 3 times
[ { _id: 'sec123', count: 3 } ]
I would like to decrement count by one, so in this case and not do anything otherwise…
[ { _id: 'sec123', count: 2 } ]
how to modify to decrement when it is saying:
Error reason in END_date logic is : { [MongoError: exception: unknown group operator ‘$inc’]
async function decrementUserIdCount(userid) {
var promise = await new Promise(function (resolve, reject) {
FutureTasks.aggregate(
[
{
$match: {
"userid": {$eq: userid}
}
},
{
$group: {
_id: "$userid", count: {$inc: -1}
}
}
]
,(err, db) => {
err ? reject(err) : resolve(db);
});
});
return promise;
}