<p>Sadly this is not possible currently, there is an open feature request on it <a href="https://jira.mongodb.org/browse/SERVER-22497" rel="nofollow noreferrer">here</a> so you can keep track of it if you wish.</p>

<p>Right now thought you have two options.</p>

<ol>
<li><p>Split your call into 2 queries and add that bit of logic to your code, which is what i personally recommend.</p></li>
<li><p>Use this aggregate which looks up all 3 collections:</p></li>
</ol>

<pre><code>search.aggregate([
    {
        '$match': {
            'id_int': 0
        }
    },
    {
        '$project': {
            '_id': 0,
            'collection': 1,
            'id_int': 1
        }
    },
    {
        "$facet": {
            "arxiv": [
                {
                    "$lookup": {
                        "from": "arxiv",
                        "localField": "id_int",
                        "foreignField": "id_int",
                        "as": "arxiv"
                    }
                }
            ],
            "crossref": [
                {
                    "$lookup": {
                        "from": "crossref",
                        "localField": "id_int",
                        "foreignField": "id_int",
                        "as": "crossref"
                    }
                }
            ],
            "pmc_test": [
                {
                    "$lookup": {
                        "from": "pmc_test",
                        "localField": "id_int",
                        "foreignField": "id_int",
                        "as": "pmc_test"
                    }
                }
            ]
        }
    },
    {
        "$addFields": {
            "newRoot": [
                {
                    "k": "$collection",
                    "v": {
                        "$cond": [
                            {
                                "$eq": [
                                    "$collection",
                                    "arxiv"
                                ]
                            },
                            "$arxiv",
                            {
                                "$cond": [
                                    {
                                        "$eq": [
                                            "$collection",
                                            "crossref"
                                        ]
                                    },
                                    "$crossref",
                                    "$pmc_test"
                                ]
                            }
                        ]
                    }
                },
                {
                    "k": "collection", "v": "$collection"
                },
                {
                    "k": "id_int", "v": "$id_int"
                }
            ]
        }
    },
    {
        "$replaceRoot": {
            "newRoot": {
                "$arrayToObject": {
                    "$concatArrays": "$newRoot"
                }
            }
        }
    }
])
</code></pre>

<p>As you might have noticed the pipeline isn't exactly sexy, if you don't care about the field name in the end result you can dump most of it.</p>
Dynamic from in $lookup
<p>I am trying to see if i can change the <strong>from</strong> in the <strong>$lookup</strong> or rearrange my query to somehow retrieve from three potential collections. So far i have managed to set up the query like so:</p>

<pre><code>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) ... )
</code></pre>

<p>The <strong>$match</strong> and then <strong>$project</strong> pipeline stages return a result with the following properties:</p>

<pre><code>collection:"arxiv"
id_int:0 
</code></pre>

<p>The collection value will always be one of three arxiv, crossref or pmc_test. Therefore i'd like my <strong>$lookup from</strong> to use this property value programmatically as opposed having it hard coded.</p>

<pre><code>'$lookup': {
   'from': 'arxiv' or 'crossref' or 'pmc_test', // Dynamic based on result
   ...
}
</code></pre>

<p>Thanks</p>

<p><strong>Edit</strong></p>

<p>id_int will get passed in and collection will not, thats why a query is made to the search collection.</p>