search

Home  >  Q&A  >  body text

mongodb - e-commerce platform, how is the monthly sales volume of products calculated?

For example, the total sales volume in a month is 500 pieces. On February 1st, the sales volume was 11 pieces, but on March 1st, it was only 10 pieces. Then after March 1st, the total sales volume will become 499 pieces.
Write a scheduled task to update every morning, 30 days from today, and calculate monthly sales based on the order volume in the previous 30 days? Or can we count monthly sales in real time?

Similarly, how are the monthly views of general videos or articles calculated?

巴扎黑巴扎黑2746 days ago830

reply all(1)I'll reply

  • 世界只因有你

    世界只因有你2017-05-17 10:04:35

    Although I don’t fully understand what you mean, this is how it is done sometimes. For example:

    { 产品:String,
      销量:[{日期:'3月1日',销量:100},
            {日期:'3月2日',销量:50},
            ...
            ....
            ],
      总计销量:number
    }
    

    The summary sales volume can be updated in real time using update + $inc.

    For reference.

    Love MongoDB! Have fun!

    reply
    0
  • Cancelreply