Show
db.test.insert({ foo: [1, 2] })
db.test.insert({ bar: 1 })
db.test.aggregate([
{
$match: {
foo: 1
}
},
{
$lookup: {
from: 'test',
let: {
arr: '$foo'
},
pipeline: [
{
$match: {
bar: {
$in: '$$arr'
}
}
}
],
as: 'result'
}
}
])
and it will throw:
{
"operationTime" : Timestamp(1526389658, 1),
"ok" : 0.0,
"errmsg" : "$in needs an array",
"code" : NumberInt(2),
"codeName" : "BadValue",
"$clusterTime" : {
"clusterTime" : Timestamp(1526389658, 1),
"signature" : {
"hash" : BinData(0, "AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
but projection shows:
db.test.aggregate([
{
$match: {
foo: 1
}
},
{
$lookup: {
from: 'test',
let: {
arr: '$foo'
},
pipeline: [
{
$match: {
bar:1
}
},
{
$project: {
arr: '$$arr'
}
}
],
as: 'result'
}
}
])
that $$arr is in fact an array:
{
"_id" : ObjectId("5afad86a91c788853024d506"),
"foo" : [
1.0,
2.0
],
"result" : [
{
"_id" : ObjectId("5afadc2c91c788853024d507"),
"arr" : [
1.0,
2.0
]
}
]
}