【发布时间】:2021-04-29 00:31:29
【问题描述】:
if (reaction.emoji.name === '✅') {
if (user.id == persToProp) {
await Reply.delete()
var date = new Date();
var today = date.getDate();
await mongo().then( async (mongoose) => { //line 76
try {
await marriageListSchema.findOneAndUpdate( //line 78
{
_id: message.author.id,
},
{
partener: persToProp,
},
{
marriageDate: today,
},
{
upsert: true,
}).exec();
} finally {
mongoose.connection.close()
}
}).catch( err => {
console.log(err);
});
我收到此错误,但我不明白为什么
MongooseError: Callback must be a function, got [object Object] 在 Function.Model.$handleCallbackError (A:\DiscordBot\node_modules\mongoose\lib\model.js:4857:11) 在 Function.Model.findOneAndUpdate (A:\DiscordBot\node_modules\mongoose\lib\model.js:2464:19) 在 A:\DiscordBot\commands\propose.js:78:58 在 processTicksAndRejections (internal/process/task_queues.js:93:5) 在异步客户端。 (A:\DiscordBot\commands\propose.js:76:25)
【问题讨论】:
-
我记得在使用 SQLite 时遇到了类似的错误。确保您的所有语法都是正确的 - 因为当您尝试调用对象中的方法而不指定您正在调用的对象的哪个部分时,会发生 [object, Object] 错误 - 例如
var car = {type:"Fiat", model:"500", color:"white"};然后你调用car而不是调用car.type。 -
你传递给函数的对象太多了。
标签: mongoose discord.js