我有一个用户表,每行看起来像这样:
{
id: <user's id>,
email: <user's email>
}
id
是主键, email
有二级索引 .
我想仅在没有其他用途存在同一电子邮件的情况下添加用户 . 通常我会使用两个查询: getAll(<user's email>, {index: 'email'})
以确保不接收电子邮件,然后是 insert({email: <user's email>}
但这些是两个单独的查询(即不是原子操作) .
Is there a way to check-and-set atomically using getAll?
注意:我知道可以使用 get
执行此操作,如here所示,但这不适用于 getAll
1 回答
不幸的是,你不能对二级索引进行原子操作 . 最好的办法可能是添加另一个
emails
表,其中主键是电子邮件地址 .