It would be great to add to the readme how to define models with BaseModel
my model is
export default class User extends BaseModel {
email: string
password: string
rememberMeToken: string | null
createdAt: Date
updatedAt: Date
status: StatusEnum = StatusEnum.Pending;
static async hashPassword(user: User) {
if (user.$dirty.password) {
user.password = await Hash.make(user.password)
}
}
static async isEmailTaken(email: string, excludeUserId) {
const user = await this.find({ email, _id: { $ne: excludeUserId } });
return !!user;
}
}
error thrown
err: {
"type": "MongoInvalidArgumentError",
"message": "Collection name must be a String",
"stack":
MongoInvalidArgumentError: Collection name must be a String
at checkCollectionName (/var/www/html/adonis/node_modules/mongodb/src/utils.ts:84:11)
at new Collection (/var/www/html/adonis/node_modules/mongodb/src/collection.ts:174:24)
at Db.collection (/var/www/html/adonis/node_modules/mongodb/src/db.ts:298:12)
at Connection.collection (/var/www/html/adonis/node_modules/@zakodium/adonis-mongodb/src/Database/Connection.ts:121:15)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at Function.find (/var/www/html/adonis/node_modules/@zakodium/adonis-mongodb/src/Model/Model.ts:406:24)
at Function.isEmailTaken (/var/www/html/adonis/app/Models/User.ts:53:18)
Your definition of the user class seems correct and it runs without errors on my end if I replace this.find with this.query.
I suspect that you are using an old version of the package.
Hello Am getting this error
It would be great to add to the readme how to define models with BaseModel
my model is
error thrown