I have a collection of songs that I want to present to a user. Each song is associated with a specific id. The issue I am encountering is that some songs should be displayed multiple times. Currently, I am using the $in
operator in my MongoDB query, but it only returns three unique song ids, limiting the number of objects returned to just three. Consequently, when I use spacebars to iterate over these objects in my template, I am unable to display the same song multiple times. Any guidance on how to resolve this would be greatly appreciated.
Current Song Display Order:
- My Everything
- This an That
- Going off Again
Desired Song Display Order:
- My Everything
- My Everything
- This an That
- Going off Again
Below is the code snippet I am using:
Template.songList.helpers({
songs: function () {
var idsOfSongs = ["cEbeGLR5ujCEFPtnH", "cEbeGLR5ujCEFPtnH", "qcRfAPeYMQycwodLA", "7oK4TKZiEfvZoC5Jz"]
return Songs.find({"_id":{$in: idsOfSongs}}).fetch();
}
});
Objects returned from Songs.find:
[Object, Object, Object]
0: Object
_id: "cEbeGLR5ujCEFPtnH"
album: "My Everything"
artist: "Ariana Grande"
1: Object
_id: "qcRfAPeYMQycwodLA"
album: "This an That"
artist: "Mark Miller"
2: Object
_id: "7oK4TKZiEfvZoC5Jz"
album: "Going off Again"
artist: "Pick up Sticks"