Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collection name must be a String #148

Open
q8tywolf opened this issue Jun 8, 2023 · 1 comment
Open

Collection name must be a String #148

q8tywolf opened this issue Jun 8, 2023 · 1 comment

Comments

@q8tywolf
Copy link

q8tywolf commented Jun 8, 2023

Hello Am getting this error

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)
@targos
Copy link
Member

targos commented Jun 14, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants