I have a star rating system for users, and I want to save the count for each star in my User schema. For example 5 stars have 3 count, 2 stars have 0 count and I want to save that in the following structure:
{ 5: 3, 2: 0, ... }
I am struggling to add a dynamic key to my mongoose Structure
Here is my alternative approach in my user model:
ratingCount: {
type: [
{
rating: {
type: String,
enum: [5, 4, 3, 2, 1],
},
count: Number,
},
],
},
If there is no alternative to my approach, I can modify it in the FE. But another approach will make it easier.
Thank you.