从Postgres迁移到MongoDB

从Postgres迁移到MongoDB,mongodb,Mongodb,需要更好的迁移解决方案 说明:用户邮件地址验证服务 问题:Postgres中pl/pgSQL过程中存储的业务逻辑 步骤: 1. Insert into table user Email address and randomly generated hash 2. Send verification/confirmation Email with URL path and hash argument 3. Recv HTTP request with hash: hash equals

需要更好的迁移解决方案

说明:用户邮件地址验证服务

问题:Postgres中pl/pgSQL过程中存储的业务逻辑

步骤

1. Insert into table user Email address and randomly generated hash

2. Send verification/confirmation Email with URL path and hash argument

3. Recv HTTP request with hash:
    hash equals - Update record: CONFIRMED, return success
    hash not found - Return error

4. Send response (error or success HTML page)
servlet逻辑的详细信息(步骤3,4):

-Servlet call pl/pgSQL procedure with received hash as argument

-Postgres stored procedure doing:
  SELECT record by hash
  if FOUND
    DELETE temporary hash data
    UPDATE email address as verified
    return FOUND
  if NOT_FOUND
    return NOT_FOUND

-Servlet return success or fail HTML page.
我认为,在mongoDB迁移中,我需要将一些逻辑从pl/pgSQL过程转移到Javaservlet

是吗?

是的,你是对的

不要在数据库中存储应用程序逻辑。在MongoDB内部运行JavaScript存在性能限制


我将这种情况称为存储过程的使用。允许在客户端执行此操作,不存在一致性问题。如果用户使用另一个浏览器/窗口,则他们会注意到它,并返回一个错误,说明“oops,token现在无效”。这远远超过了存储过程的使用