MongooseError:Model.findOne()不再接受回调(计数Scheme)

问题描述 投票:0回答:1

This is the error code im getting

This is the code

这真的让我很困惑,我不知道为什么他们删除了这个选项,或者用什么来替换它,我知道它已被删除,但我不知道如何修复它

如果有人能提供帮助那就太好了

我尝试过更换并调整它,但效果不佳

javascript mongoose mongoose-schema
1个回答
0
投票

Mongo 从 5.0 版本开始不再支持其 Node.js 驱动程序的回调,转而采用仅 Promise 的公共 API。 Mongoose 在 v7 中也放弃了回调支持,因此

findOne()
和其他方法现在总是返回一个承诺: MongooseError: Model.findOne() 不再接受 Function 处的回调

异步/等待

async function tetsing(guilId) {
  try {
    const data = await countingScheme.findOne({ GuildID: guilId });
    /* ... */
  } catch(err) {
    /* ... */
  }
}

然后/抓住

countingScheme.findOne({ GuildID: guilId })
  .then((data) => { /* ... */ })
  .catch((err) => { /* ... */ });

异步

countingScheme.findOne({ GuildID: guilId })
  .then(async (data) => { /* ... */ })
  .catch((err) => { /* ... */ });
© www.soinside.com 2019 - 2024. All rights reserved.