I have documents in a collection that contain an array of objects. Each object in the array contains a date field. I want to update this array with a new object if the date is new, if it isn't I want to update the object with the same date in the array...
Here's an example schema:
const ExampleSchema = new Schema(
{
name: { type: String },
members: [{ roleId: String, roleName: String, quantity: Number, color: String }],
dailyLogs: [{ members: Number, verifiedMembers: Number, date: String }]
},
);
I want to end up with an array that creates an object if the date doesn't exist, and if it exists I want to update the object with that date
name: 'name',
members: [...],
dailyLogs: [
{
members: 4,
verifiedMembers: 2,
date: '02.13.2022'
},
{
members: 8,
verifiedMembers: 5,
date: '02.14.2022'
},
]