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})
答案 0 :(得分:2)
对播放列表对象使用.dot
表示法
await MusicModel.findOneAndUpdate(
{ "_id": input.music },
{ "playlists.type1": { "$push": type1._id }},
{ "new": true }
)