mongoose - Reference a nested schema in moongose -
I have an album schema in which the song has a sub-plan
albums album album name : Song: [{Name, URL}]
I have another archive that has the schematic of the playlist. In this schema, each document has to catch an array of songs.
playlist scheme playlist name: song: []
How do I go about referencing songs from playlists, so that I use the poplit on the playlist Can i do Is there any way to do this without breaking the song in its collection? I have tried to find SO and mungdo docs, but there is not a way to do so by now.
Note: This question was marked as a duplicate. this ! The question which is related to the moderator, is asking how to present the references in one collection to another collection. This question is about referencing a sub-document in a collection from the second collection. There are two very different things.
You can not have a reference to sub-documents, there is no way around it So you can not use the population You will need a query on the album
collection and use the project
( $ elemMatch
). If you want to use populate
, consider changing your schema.
Comments
Post a Comment