Get back matched array elements present in a document's field which is also an array
<p>I have an <strong>array defined below</strong> which contains some strings,</p>

<pre><code>arr = ["hola", "hii", "hey", "namaste"];
</code></pre>

<p>Now below are the <strong>documents i have in mongodb</strong></p>

<pre><code>{
    "user_id": "Michael",
    "list": ["hola", "ola", "hey", "maybe"]
}
</code></pre>

<p>Now i want to write a query in mongodb which returns all "arr" elements which are also present in "list" of the particular "user_id".</p>

<p><strong>So My Desired Output is</strong></p>

<pre><code>_id: "_id" : ObjectId("5828ae4779f2e01b06bb7a61"), results: ["hola", "hey"]
</code></pre>

<p>i wrote below query using aggregation but i am getting error as </p>

<pre><code>MongoError: FieldPath field names may not start with '$'
</code></pre>

<p><strong>My code</strong></p>

<pre><code>arraymodel.aggregate(
        { $match: { user_id: "Michael" }},
        { $unwind: '$list'},
        { $match: {list: {$in: arr}}},
        { $group: {_id: '$_id', results: {$push: '$list.$'}}},
        function(err, docs) {
            if (err) {
                console.log('Error Finding query results');
                console.log(err);
            } else {
                if (docs) {
                    console.log('docs: ', docs);
                } else {
                    console.log('No Arr Found');
                }
            }
        }
        );
</code></pre>