Hi,
Using Mongo 3.6.5
I am using $lookup in an aggregation pipeline. Can't get this to work:
db.getCollection('sensor_data').aggregate(
[
....
{$lookup:{
from:'sites',
let: { z: '$zone'},
pipeline: [
{$match: { _id : '$$z'}},
],
as: 'apInfo'
}},
]
$zone is an ObjectID in the sensor_data document.
If, I do this:
db.getCollection('sensor_data').aggregate(
[
....
{$lookup:{
from:'sites',
let: { z: '$zone'},
pipeline: [
{$project: { t : '$$z'}},
],
as: 'apInfo'
}},
]
I get what you would expect ... apInfo is an array with _id being the ObjectID and t being the zone...
{
"_id" : {
"mac" : NumberLong(260515773225939),
"ts" : ISODate("2018-07-07T16:32:49.000Z")
},
"zone" : ObjectId("5af1b83c1c2d750008146c3f"),
"apInfo" : [
{
"_id" : ObjectId("5ac3f91f3314940008ab61d3"),
"t" : ObjectId("5af1b83c1c2d750008146c3f")
},
{
"_id" : ObjectId("5af1b83c1c2d750008146c3f"),
"t" : ObjectId("5af1b83c1c2d750008146c3f")
}, ...
Any suggestions?
Steve