gpt4 book ai didi

javascript - Mongoose 错误 : Operation 'featureds.find()` buffering timed out after 10000ms

转载 作者:行者123 更新时间:2023-12-05 00:27:40 26 4
gpt4 key购买 nike

我在 MongoDB 上有一个集合,我尝试使用 find() 查询所有元素:

const mongoose = require('mongoose');
const Featured = mongoose.model('featured');
module.exports = app => {
app.get('/api/featured', async (req, res) => {
console.log("featured route");
const featured = await Featured.find();
console.log(featured);
res.send(featured);
})
}

这是 Featured.js:
const mongoose = require('mongoose');
const { Schema } = mongoose;

const featuredSchema = new Schema({});

mongoose.model('featured', featuredSchema);
但是,我在提出请求时收到错误:
(node:75568) UnhandledPromiseRejectionWarning: MongooseError: Operation `featureds.find()` buffering timed out after 10000ms
at Timeout.<anonymous> (/Users/prikshetsharma/Desktop/humboiserver/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:184:20)
at listOnTimeout (internal/timers.js:554:17)
at processTimers (internal/timers.js:497:7)
(node:75568) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)

如何修复此错误并让所有收藏项返回 find() ?奇怪的是,错误显示 featureds.find()而我从未在任何地方的代码中使用过特色词。

最佳答案

对于可能偶然发现此问题的其他人:我的问题与连接错误有关,我设法通过使用 mongoose.connect 修复它而不是 mongoose.createConnection .
请注意 Mongoose documentation saying :

Mongoose will not throw any errors by default if you use a model without connecting.


...这只会导致缓冲超时。

关于javascript - Mongoose 错误 : Operation 'featureds.find()` buffering timed out after 10000ms,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65418250/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com