I am trying to build a shopping cart system through a Mongodb.
During the purchase of a customer he will be able to add products to the cart but there will be time to purchase the product otherwise the system will release the product.
My idea is to create an array of products in the database when it is initialized with zeros or null. When a customer adds a product to the cart, he will update the cell in the array to the user number, but the update will only be valid for 10 minutes.
Look like :
["Product 1" : null,
"Product 2" : null,
"Product 3" : null ]
After the user added product 2 to cart.
["Product 1" : null,
"Product 2" : "Taken",
"Product 3" : null ]
Now when another customer enters the site he will not be able to order this product since it is occupied by another customer.
So far I'm fine, but how can I do that after 10 minutes the product will be released - meaning it will be back to 0 or null.
Thanks.
question from:
https://stackoverflow.com/questions/65545804/update-array-in-mongodb-by-time-interval-shopping-cart-system 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…