0

I have an array of stages in my MentorProfile document and I want to concatenate lessonsWithComments array with stages. Is this even possible without having to loop through the lessonsWithComments and then querying for each iteration with updateMany

MentorProfile.updateMany(
                {},
                {
                    $push: {
                        stages: {
                            lessonsWithComments
                        }
                    }
                }
            ).then((update) => res.json(update));
Snoopy
  • 1,257
  • 2
  • 19
  • 32

1 Answers1

1

I hope this helps you.

MentorProfile.updateMany(
   {},
   { $push: { stages: { $each: lessonsWithComments } } }
).then((update) => res.json(update));

See: https://docs.mongodb.com/manual/reference/operator/update/push/

A''
  • 93
  • 2
  • 9