Adminjs无法从mongo数据库中获取数据.(NestJS)



我在nestjs和mongoose中使用adminjs

这是我的产品模型const ProductModel = model<IProduct>('product', ProductSchema);

this is my resource

resources: [
{
resource: ProductModel,
options: { 
navigation: { name: null }, 
show: {
before: async (request, response, context) => {
throw new Error(
'Data fetching has been disabled for this resource',
);
},
handler: async (request, response, context) => {
return {
records: [],
};
},
},
list: {
before: async (request, response, context) => {
throw new Error(
'Data fetching has been disabled for this resource',
);
},
handler: async (request, response, context) => {
return {
records: [],
};
},
},
},
]```


this is error i get 

[Nest] 23592 - 04/12/2023, 11:16:57 AM ERROR [ExceptionsHandler]操作products.find()缓冲在10000ms后超时MongooseError:操作products.find()缓冲超时10000ms后在超时。用户(C: 用户文档 后端 node_modules 猫鼬 lib node-mongodb-native collection.js司机:185:23)在listOnTimeout (node:internal/timers:559:17)@ processTimers (node:internal/timers:502:7)


how to resolve this? 

我已经解决了错误。

我让adminjs模块在初始化前等待5秒:

import { AdminModule as AdminJsModule } from '@adminjs/nestjs';
import { adminModuleOptions } from './admin-module.options';
AdminJsModule.createAdminAsync({
useFactory: async () => {
await new Promise((resolve) => setTimeout(resolve, 5000));
return adminModuleOptions;
},
}),

然后我让mongoose模块在连接前等待5秒:

MongooseModule.forRootAsync({
useFactory: async (): Promise<MongooseModuleOptions> => ({
uri: mongoCredentials.url,
connectionFactory: () => {
const connection = mongoose.connection;
setTimeout(() => mongoose.connect(mongoCredentials.url), 5000);
return connection;
},
}),
}),

相关内容

  • 没有找到相关文章

最新更新