So, I'm adding a premium remove command, so that I can remove premium from users at any given time. However, I tried it and it responded with this error:
Discord.js MongooseError: Callback must be a function, got [object Object]
How can I fix this?
await mongo().then(async (mongoose) => {
try {
await premiumSchema.deleteOne({
userID: user.id
}, {
userID: user.id,
username: user.username
}, {
upsert: true
})
} finally {
mongoose.connection.close();
}
})
.deleteOne()
accepts three parameters; a filter object, an options object, and a callback function. You pass an object as the third parameter ({ upsert: true }
) and that's why Mongo is complaining that a callback must be a function, got [object Object]
.
It looks like you just replaced an updateOne
or findOneAndUpdate
method with a deleteOne
and haven't checked the documentation how to use it.
I'm not sure what you're trying to delete. If it's a document with a certain userID, you can use the following:
try {
await premiumSchema.deleteOne({ userID: user.id });
} finally {
// ...
}