Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

134
Views
Update an array of objects to store daily data, Mongoose

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'
},
]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use $addToSet for that,

db.collection.update({_id:"yourId"}, {$addToSet:{members: "yourMembers", verifiedMembers: "yourVerifiedMembers", dailyLogs:{date: "yourDate"}}});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!