Hello teams! Have a chobo question here.. ```model...
# orm-help
p
Hello teams! Have a chobo question here..
Copy code
model Role {
  id                  String            @id @default(auto()) @map("_id") @db.ObjectId
  name                String  
  // ****************************************************
  application         Application       @relation(fields: [applicationId], references: [id])
  applicationId       String    
  user                User[]            @relation(fields: [userIds], references: [id])
  userIds             String[]          @db.ObjectId

  @@index([applicationId])
  @@index([userIds])
  @@index([applicationId, userIds])
}
This is a Role schema for mongodb. when I index like above, does it mean Im indexing applicationId only, and userIds only, and both combined applicationId and userids togerther?? So my purposes are 1. i want to get all users in the application (that is why i index @@index([applicationId]) 2. I want to get all applications that a user belong to (@@index([userIds]) 3. I want to check if a user exists in application (@@index[userids, applicationId]) Is it too much indices? should i get rid of @@index([appicationId, userIds])?? Thank you in advance!!
n
Hey đŸ‘‹ That’s an excellent question! Indexes are generally created for faster retrieval of data. You should be making decisions on creating indexes based on the queries which you are invoking. If you are using applicationId, userId in the
where
clause then it would make sense to create an index on them. You can look at the Query Plan of your MongoDB query to check if the indexes that you have created are being used or not.