When i update the ttl of a user the unique becomes useless and i can create more users with the same email

When i update the ttl of a user the unique becomes useless and i can create more users with the same email

i have this index the same index that the docs have
CreateIndex({
name: “users_by_email”,
source: Collection(“users”),
terms: [{field: [“data”, “email”]}],
unique: true,
})

when i create a user i do it like this

const newUser = await faunadbClient.query(
q.Create(q.Collection(“users”),{
credentials:{password: req.body.password},
ttl:q.TimeAdd(q.Now(),15,“minute”),
data:{email:req.body.email, name:req.body.name}
})
)
in this step if i try to create 2 users with same email it will give the error instance not unique what is nice, then i want to verify the email of then user soo i send an email and if the user doesnt verify in 15 mins the ttl will delete the user my idea was to do this

const user = await faunadbClient.query(
q.Update(
q.Ref(q.Collection(“users”),parsedRef),
{
ttl:null
}
)
)
soo i delete the ttl and the user wont be deleted but when i update the ttl the index becomes useless and i can create another one user with the same email and i can delete the ttl in that one to soo i can make a third user with same email repeat and then have four etc … infinite users with same email when it should be unique the user objects are like this
without ttl
{
ref: Ref(Collection(“users”), “296964868965138944”),
ts: 1619466722850000,
data: { email: ‘koltisb@gmail.com’, name: ‘koltisb@gmail.com’ }
}
with ttl
{
ref: Ref(Collection(“users”), “296965764069458432”),
ts: 1619467472060000,
ttl: Time(“2021-04-26T20:19:32.041Z”),
data: { email: ‘koltisb@gmail.com’, name: ‘koltisb@gmail.com’ }
}
soo they have same email and data but the index is not saying instance not unique just couse the ttl, is this a bug or im doing something wrong?

This sounds like a bug. We’ve filed an issue, ENG-2764, and we’ll let you know when we have a diagnosis.

1 Like