title: Sorting inside a document in Yii2 mongodb
body: <p>I am doing an application with Yii2 and mongodb.I want to retrieve records of a client based on id and sort the events of that client by date in descending order.But my code is not working.Please help me to find the issue.</p>
  
  <p>The 'client' Collection's document is given below</p>
  
  <pre><code>{
      "_id" : ObjectId("55c397646ac8e41812000029"),
      "name" : "Krishnapriya",
      "location" : "Karunagapalli",
      "address" : "",
      "phoneno" : [ 
          "8765456789"
      ],
      "email" : [ 
          "kp@gmail.com"
      ],
      "category" : "0",
      "notes_on_user" : "",
      "event" : [ 
          {
              "event_title" : "Sony Home Theater",
              "event_call_or_visit_purpose" : "2",
              "event_notes" : "She enquired about new Sony XXX 5.1 Channel Home theater",
              "event_call_or_visit" : "1",
              "event_datetime" : ISODate("2015-08-06T17:23:46.000Z")
          }, 
          {
              "event_title" : "San Disk Pendrive",
              "event_call_or_visit_purpose" : "1",
              "event_notes" : "She wants the pendrive to be repaired by 2 days",
              "event_call_or_visit" : "2",
              "event_datetime" : ISODate("2015-08-06T17:31:07.000Z"),
              "item" : {
                  "item_name" : "San Disk 4gb",
                  "item_model" : "San disk",
                  "item_description" : " Pendrive not in reading condition",
                  "item_accessories" : []
              }
          }
      ]
  }
  </code></pre>
  
  <p>Here I want to get the  document's 'event' array sorted with 'event_datetime' field in descending order .My controller code is given below.</p>
  
  <pre><code>       $clientdetail = Yii::$app-&gt;mongodb-&gt;getCollection('client');
         $result = $clientdetail-&gt;find(["_id" =&gt;$id])-&gt;sort(["event.event_datetime"=&gt; -1]);
  
         Yii::$app-&gt;response-&gt;format = \yii\web\Response::FORMAT_JSON;
         return $result;
  </code></pre>