Sort using a field in an embedded doc in an array without considering other equivalent fields in mongodb
<p>I have collection called <code>Products</code>.
Documents of <code>Products</code> look like this:</p>

<pre><code>{
    id: 123456,
    recommendationByCategory: [
        {   categoryId: a01,
            recommendation: 3
        },
        {
            categoryId: 0a2,
            recommendation: 8
        },
        {
            categoryId: 0b10
            recommendation: 99
        },
        {
            categoryId : 0b5
            recommendation: 1
        }
    ]
}
{
    id: 567890,
    recommendationByCategory: [
        {   categoryId: a7,
            recommendation: 3
        },
        {
            categoryId: 0a2,
            recommendation: 1
        },
        {
            categoryId: 0b10
            recommendation: 999
        },
        {
            categoryId : 0b51
            recommendation: 12
        }
    ]
}
</code></pre>

<p>I want to find all the docs that contain <code>categoryId: 0a2</code> in <code>recommendationByCategory</code>, but want to get <em>sorted</em> using the <code>recommendation</code> of the <code>category 0a2</code> <strong>alone</strong> in asc order. It must not consider <code>recommendations</code> of other <code>categoryId</code>. I need id: 567890 followed by id: 123456.
I <em>cannot</em> use aggregation. Is it possible using Mongodb/Mongoose? I tried giving sort option of <code>'recommendationByCategory.recommendation: 1'</code> but it's not working.</p>

<p><strong>Expected Query:</strong> <code>db.collection('products').find({'recommendaionByCategory.categoryId': categoryId}).sort({'recommendationByCategory.recommendation: 1'})</code></p>

<p><strong>Expected Result:</strong></p>

<pre><code>[
    {doc with id:567890},
    {doc with id: 123456}
]
</code></pre>