Hi,
I’m using an aggregation to replace ObjectIds in one collection with entries in another collection. The stories collection has the following structure:
{
_id: new ObjectId("62e82d326f664edd9b96f33a"),
title: 'Test 0',
description: '...',
user_id: new ObjectId("62e82d326f664edd9b96f330"),
entries: [
new ObjectId("62e82d6d0f5748cbefb0a4a3"),
new ObjectId("62e82f8c1b832b9714edf574"),
new ObjectId("62e82f8c1b832b9714edf577"),
new ObjectId("62e82fcc5c3e92e184d5c733"),
new ObjectId("62e830535297f48e35d47629")
]
The entries array are the _ids of the entries in the entries collection:
{
_id: new ObjectId("62e830535297f48e35d47629"),
beginTime: 2022-08-01T19:58:11.772Z,
endTime: 2022-08-01T19:58:11.772Z,
content: [Object],
mapView: [Object],
stories: [Array]
}
My aggregation is the following:
[
{
$match: {
_id: new ObjectId('62e82d326f664edd9b96f33a')
}
},
{
$lookup: {
from: 'entries',
localField: 'entries',
foreignField: '_id',
as: 'entries2'
}
}
]
I would expect, that the result (entries2) contains 5 entries, but instead the array has only one (the last element):
{
_id: new ObjectId("62e82d326f664edd9b96f33a"),
title: 'Test 0',
description: '...',
user_id: new ObjectId("62e82d326f664edd9b96f330"),
entries: [
new ObjectId("62e82d6d0f5748cbefb0a4a3"),
new ObjectId("62e82f8c1b832b9714edf574"),
new ObjectId("62e82f8c1b832b9714edf577"),
new ObjectId("62e82fcc5c3e92e184d5c733"),
new ObjectId("62e830535297f48e35d47629")
],
entries2: [
{
_id: new ObjectId("62e830535297f48e35d47629"),
beginTime: 2022-08-01T19:58:11.772Z,
endTime: 2022-08-01T19:58:11.772Z,
content: [Object],
mapView: [Object],
stories: [Array]
}
]
}
I get the same result with compass or running it on nodejs.
Any ideas?
Carsten