Prevent the simultaneous processing of two requests Express, Node.js



  • I have a prank app. The user simply has to press the button, send a request for API to Express, the user will be involved in the MongoDB answer to the user about the successful implementation of the request.

    But if you send two such requests at one time, the user can get into one distribution two or more times.

    How can this be avoided? Is it a good way to keep a mass with users for whom such a request is already being processed? What if there are many types of requests?


  • QA Engineer

    A limitation may be added for the collection of pranks on the unique field of the user ' s name:

    db.lottery.createIndex( { "name": 1 }, { unique: true } )
    

    After which attempt to insert a document with a non-universal field name Makes a mistake, which would mean that the user is already involved in the prank. As a bonus, it can be sure that collections are always unique users, even if they are added by some other crypt (written by another software player).




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2