Unique Constraint for daily records

I have a simple model

  "LookupId": "2713b525-d8f3-4f20-8bbd-5a5ec02108c5",
  "storeDate": "2022-10-10T04:30:38.394Z",
  "count": 6871

but want to put a constraint on creating more than one LookupId per day.
If I index on storeDate then I can have a record every millisecond, I only want one LookupId records for each day.
Do I have to create another property with just the date and then index on that … or ?

I only see 2 different ways to do that.

  1. Like you mentioned, have another property, say storeDay, that is based on the date part of the storeDate.
  2. Make sure the time part of storeDate is 0 as in

I would prefer option 2.


Thanks Steeve,
I went for Option 2 which was quite easily controlled from my app

    const aDate = new Date();

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.