How can I get max value in nested documents?
<p>I have a collection(named <strong>menucategories</strong>) in MongoDB 3.2.11:</p>

<pre><code>{
    "_id" : ...
    "menus" : [
        {
            "code":0
        },
        {
            "code":1
        },
        {
            "code":2
        },
        {
            "code":3
        }
    ]
},
{
    "_id" : ...
    "menus" : [
        {
            "code":4
        },
        {
            "code":5
        },
        {
            "code":6
        },
        {
            "code":7
        }
    ]
},
{
    "_id" : ...
    "menus" : [
        {
            "code":8
        },
        {
            "code":9
        },
        {
            "code":10
        },
        {
            "code":11
        }
    ]
}
</code></pre>

<p>Every <strong>menucategory</strong> has array named <strong>menus</strong>. And every menu(element of the array) has <strong>code</strong>. The '<strong>code</strong>' of menus is unique in every <strong>menu</strong>. I wanna get the maximum value of menu's code(in this case, <strong>11</strong>). How can I achieve this?</p>