Hi all, Optional Unique ( String? @unique) not wo...
# mongodb
m
Hi all, Optional Unique ( String? @unique) not working in MongoDB , any one have the same issue ? As per prisma doc, " It will create two new records where the email is set to NULL in the database" using the optional unique constraint Issue raised in GitHub, https://github.com/prisma/prisma/issues/12827 schema :
Copy code
model User {
  id    String  @id @default(auto()) @map("_id") @db.ObjectId
  email     String?  @unique
  mobile    String?  @unique
}
NOTE:
As noted in the query coverage documentation for partial indexes:
Since MongoDB will not use the partial index for a query or sort operation if using the index results in an incomplete result set.
To use the partial index, a query must contain the filter expression (or a modified filter expression that specifies a subset of the filter expression) as part of its query condition.
EX. to use partial index for
$type
filter you have to use below filter:
{ "email": { "$eq": "foo@mail.com", "$type": "string" } }
// or
{ $and: [{ "email": "foo@mail.com" }, { "email": { $type: "string" } }] }
Playground
v
@Matt Mueller (Prisma Client PM) FYI ^^
j
Note there is an open question in the issue for @Muhad B K: https://github.com/prisma/prisma/issues/12827#issuecomment-1102530401