I am trying to see if i can change the from in the $lookup or rearrange my query to somehow retrieve from three different collections. So far i have managed to set up the query like so:
const search = db.collection("search");
search.aggregate([
{
'$match': {
'id_int': 0
}
}, {
'$project': {
'_id': 0,
'collection': 1,
'id_int': 1
}
}, {
'$lookup': {
'from': 'arxiv',
'localField': 'id_int',
'foreignField': 'id_int',
'as': 'arxiv'
}
}
], function(err, cursor) ... )
The $match and then $project pipeline stages return a result with the following properties:
collection:"arxiv"
id_int:0
The collection value will always be one of three arxiv, crossref or pmc_test. Therefore i’d like my $lookup from to use this property value programmatically as opposed having it hard coded.
Thanks