简体   繁体   中英

MongoDB design for real time reporting system

I've a requirement to give an hourly (daily, weekly in future) report for the coupon code redemption for a campaign. A campaign can have multiple coupon codes.

I am planning to use MongoDB and have two approaches in my mind:

  1. Store each redemption details in one document and query on the same based on search criteria.
  2. Create a single document for an hour and have the redemption detail as a nested document. Here key of the document will be campaign id start time and end time. Nested document representing each redemption will be same as in approach 1.

Is there any advantage of second approach in terms of performance. On an average the total number of redemption in an hour will be 1000 and maximum redemption for a campaign will be 1 million.

I will have to consider the size limit of 16 MB for a single document in MongoDB as well.

Please help me designing this solution.

Regards, Abhishek

I suggest you use the first approach you mentioned, as you will not have that big amount of data. If you ensureIndex then it will take milliseconds to run either of those searches. We have been working with MongoDB for a while and we are working with results of over 20M records and it takes less than a second to retrieve data from a search and it makes it more clear and cleaner in the case you want to change your queries in the future.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM