I'm trying to join some items from one collection to another. The original collection has nested arrays that I'm trying to join on from the other collection.
My data looks like this:
Feed
{
name: "feed name",
carousels: [
{
name: "Top 5",
items: [
{
_id: ObjectId("id of some soundpack")
},
{
_id: ObjectId("id of some other soundpack")
}
]
},
{
name: "Latest",
items: [
{
_id: ObjectId("id of some soundpack")
},
{
_id: ObjectId("id of some other soundpack")
}
]
}
]
}
Soundpack
{
_id: ObjectId("some object id"),
name: "soundpack name 1",
url: "http://www.somewebsite.com",
image: "http://www.image.com"
},
{
_id: ObjectId("some object other id"),
name: "soundpack name 2",
url: "http://www.somewebsite.com",
image: "http://www.image.com"
},
{
_id: ObjectId("yet another object id"),
name: "soundpack name 3",
url: "http://www.somewebsite.com",
image: "http://www.image.com"
}
And my code looks like this:
fun getFeedByName(name: String): Feed? {
return db.getCollection(FEED_COLLECTION, Feed::class.java).aggregate(listOf(
match(Feed::name eq name),
lookup (
SOUNDPACK_COLLECTION,
"carousels.items._id",
"_id",
"carousels.items"
)
)).firstOrNull()
}
For whatever reason (I've made multiple attempts at this with no luck), the join values never seem to populate into carousels.items
.
Any help here would be appreciated~