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));
0

1 Answer 1

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/

Sign up to request clarification or add additional context in comments.

1 Comment

Worked like a charm, thank you!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.