How To Solve "TypeError: Callback.apply Is Not A Function"?
I am doing a university project and I've read every post regarding my problem, but I am yet to find a solution. Maybe you can help me out. The code is the following: I get the fol
Solution 1:
You're using too many arguments.
Change this:
viewerObj.update({_id: currentIDViewerVar} , {minutesWatched: 5},{upsert:true} , function (err,result) {
if (err) throw err;
console.log("Viewer " + userNameVar + " gespeichert");
console.log("minsWatched" +minsWatched);
});
to this:
viewerObj.update({_id: currentIDViewerVar, minutesWatched: 5}, {upsert:true}, function (err,result) {
if (err) throw err;
console.log("Viewer " + userNameVar + " gespeichert");
console.log("minsWatched" +minsWatched);
});
See the docs:
Solution 2:
If you're updating a mongoose document, you don't pass in a query as the first parameter.
see the Docs for Document#update.
Thus, this update method expects 3 parameters with the
third being the callback and you pass in an object ({upsert: true}
) where the update method expects the callback. That's why you get callback.apply is not a function
. Simply because { upsert: true }
is not a function.
Solution 3:
In my case, I was facing this issue with aggregate method of mongoose (5.1.2). The same code was working on <4.9 but got broken on upgrading to 5.
I just added capital braces in my query
User.aggregate([{
$match: {
isDeleted: 0,
isActive: 1,
_id: Mongoose.Types.ObjectId(userId)
}
}, {
$project: {
claps: 1,
showIcon: { $cond: [{ $gt: [{ $size: "$userBadges" }, 0] }, 1, 0] },
}
}])
.exec(function (err, data) {});
`
Post a Comment for "How To Solve "TypeError: Callback.apply Is Not A Function"?"