title: How to sort by other field in $geonear aggregation pipeline in mongodb
body: <p>My collection has this format.</p>
  
  <pre><code>{
      "_id" : ObjectId("52e5f94d83b45407f959e7ff"),
  
      "latlng" : {
          "coordinates" : [
              85.29035240000007,
              27.6663671
          ],
          "type" : "Point"
      },
      "name" : "Sujit Maharjan",
      "updates" : [
          {
              "status" : "I want to #buy 5 kg of tomatoes.",
              "picture" : [ ],
              "parent_tweet_id" : "0",
              "deleted" : 1,
              "tweet_id" : "428578269169205248",
              "time_stamp" : 1391015996
          }
          {
              "status" : "I want to #start #milk business who can help me ?",
              "picture" : [ ],
              "parent_tweet_id" : "0",
              "deleted" : 0,
              "tweet_id" : "108fd43a-7efa-404d-800d-0c30a5da06e5",
              "time_stamp" : 1391955084
          },
          {
              "status" : "@SantoshGhimire @bhanduroshan Connect to us for  #Dairy business",
              "picture" : [ ],
              "parent_tweet_id" : "432503201968168960",
              "deleted" : 1,
              "tweet_id" : "432517594026082304",
              "time_stamp" : 1391955208
          },
          {
              "status" : "@bhanduroshan Did you get my message ?",
              "picture" : [ ],
              "parent_tweet_id" : "432502654154334208",
              "deleted" : 0,
              "tweet_id" : "432788670463377408",
              "time_stamp" : 1392019838
          },
          {
              "status" : "this is tweet with images @foodtradeHQ http://t.co/3eL1351HWf",
              "picture" : [
                  "http://pbs.twimg.com/media/BgLZ4YaCUAAsFTJ.jpg"
              ],
              "parent_tweet_id" : "0",
              "deleted" : 1,
              "tweet_id" : "433148076820156417",
              "time_stamp" : 1392105574
          }
      ]
  }
  </code></pre>
  
  <p>Now I need to query updates in which users are within certain radius sorted by updates.time_stamp.</p>
  
  <p>For this I used aggregation pipeline but $geonear query would sort from distance and limit the result.</p>
  
  <p>This is the my pipeline in python</p>
  
  <pre><code>    geo_search = {"near": [float(self.lng), float(self.lat)],
                                 "distanceField": "distance",
                                  "includeLocs": "latlng",
                                  "uniqueDocs": True,
                                  "spherical":True,
                                  "limit":100,  # this will cut off the possible results, and complexity increasing in increasing this number
                              }
  
  
  
      pipeline = []
  
      final_query = {"$and":query_string}
  
      if len(query_string)&gt;0:
          geo_search['query'] = final_query
  
  
      geo_search['maxDistance'] = 0.01261617096
  
      geo_near = {
                      "$geoNear": geo_search
                    }
  
  
      pipeline.append(geo_near)
  </code></pre>