1

I have a mongo doc with an object that holds two arrays of id's

Musics {
_id: ""evsdfbsfb"
name: "muh jams"
playlists: {
 type1: ["dfngdfgnd", "dfgdfgn"]
 type2: ['dfgndfndgn','dndgndgndgnd"]
 }
}

I've tried pushing an id like so

let music = await MusicModel.findOneAndUpdate({_id:input.music}, { playlists: { "$push": { "type1" : type1._id }}}, {new: true})

1 Answer 1

2

Use .dot notation with playlist object

await MusicModel.findOneAndUpdate(
  { "_id":  input.music },
  { "playlists.type1": { "$push": type1._id }},
  { "new": true }
)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.