Nest.js mongoose schema resource error
Describe the issue When I try to use the mongoose schema from the official Nest.js documentation Mongo with Mongoose as a resource for the Admin.js the error occurs and the Admin.js doesn't work. The error:
UnhandledPromiseRejectionWarning: TypeError: Cannot read property '
paths' of undefined
at Resource.properties (E:\web\trading\trade-auto-fly\backend\node_modules\@
adminjs\mongoose\src\resource.ts:60:55)
Installed libraries and their versions
"@adminjs/express": "^5.0.0",
"@adminjs/mongoose": "^3.0.0",
"@adminjs/nestjs": "^5.0.1",
"@nestjs/common": "^9.0.0",
"@nestjs/core": "^9.0.0",
"@nestjs/mongoose": "^9.2.0",
"@nestjs/platform-express": "^9.0.0",
"adminjs": "^6.2.3",
"express-formidable": "^1.2.0",
"express-session": "^1.17.3",
"mongoose": "^6.6.1",
"nestjs-admin": "^0.4.1",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
},
"devDependencies": {
"@nestjs/cli": "^9.0.0",
"@nestjs/config": "^2.2.0",
"@nestjs/schematics": "^9.0.0",
"@nestjs/testing": "^9.0.0",
"@types/express": "^4.17.13",
"ts-loader": "^9.2.3",
"ts-node": "^10.0.0",
"tsconfig-paths": "4.1.0",
"typescript": "^4.7.4"
},
To Reproduce Steps to reproduce the behavior:
-
Install Nest.js (latest), install Mongo/mongoose, and all the required Admin.js packages.
-
Create a Nest.js Mongoose schema as it described in the official documentation Mongo with Mongoose
-
Import the Mongoose Schema and use it as a Resource in Admin.js
-
See the error
Expected behavior
Admin.js should work fine
Screenshots
creating the Nest.js schema and using it as a resource for Admin.js:
the Error:
The Nest.js Mongo documentation page:

AdminJSOptions with schema
AdminModule.createAdminAsync({
useFactory: () => ({
adminJsOptions: {
rootPath: '/admin',
resources: [OrderSchema],
},
auth: {
authenticate,
cookieName: 'adminjs',
cookiePassword: 'secret',
},
sessionOptions: {
resave: true,
saveUninitialized: true,
secret: 'secret',
},
}),
}),
Desktop (please complete the following information if relevant):
- OS: Windows 10
- Browser: Chrome
- Version: latest
Additional context I'm wondering how to use the Nest.js mongoose implementation with the Admin.js. It looks like the Admin.js documentation is missing this chapter because the Entity way that is described in the Admin.js documentation can't be applied for the latest Nest.js mongoose approach.
Thanks for any help!
I don't really use Nest nor Mongoose much, but have you tried to pass Order instead of OrderSchema into resources? Unless @nestjs/mongoose schema is different than mongoose schema. Our current documentation (https://docs.adminjs.co/installation/adapters/mongoose) and demo app doesn't use @nestjs/mongoose
Hi @dziraf , thank you for your feedback. Yes, I tried to use the Order but it also doesn't work. Probably it's a bit different than the mongoose native stuff. So, if I understand correctly, if I want to use the Admin.js with Nest.js I shouldn't use their mongoose package but rather use the native mongoose schema, etc. ?
I'm 99.9% certain that with native mongoose package and schema it will work. Still, if it doesn't work with @nestjs/mongoose that isn't good too. It's strange though as other @nestjs/package work fine. If it's possible can you prepare a repository where I can reproduce this so I can prepare a fix?
The line which fails is: https://github.com/SoftwareBrothers/adminjs-mongoose/blob/master/src/resource.ts#L60
I'd assume that in your case this.MongooseModel is actually a schema so it doesn't have .schema property.
i had the same issue, the console said: "cannot read property 'paths' of undefined"
@dziraf Hi, I've tried to create a single dedicated repo with the minimal amount of code that contains the issue, hope it helps. If you need some help, please, let me know: https://github.com/velidan/adminjs-nestjs-mongoose-issue
to reproduce an issue:
- install node_modules
- run the mongod (mongo server)
- stand the nest.js app (yarn start:dev)
- try to open the Admin.js page http://localhost:3000/admin
Kind regards!
Is there any fix for this?
any fix for this?
Any fix for this?