Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
206 views
in Technique[技术] by (71.8m points)

node.js - Update array in mongodb by time interval (shopping cart system)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...