title: aggregate function in mongoose node.js returning no record
body: <p>I have seen few questions related to this .  But unable to find answer that can help me.</p>
  
  <p>Here is my server side node.js code using mongoose. This code is just printing "Success in fetching data[]" in the console.</p>
  
  <pre><code>var kmphDBSchema = commonRouter.kmphDBSchema;
      var locationSchema = new kmphDBSchema({result:{locations:{id:String,parent_id:String,countryCode:String,name:String}}});
      var locationModel = commonRouter.kmphMongoClient.model('mgh_locations',locationSchema);
  
  exports.getLocations =  function(request, response) { 
      var locationName = '/.*' + request.params.locationName + '.*/';
      console.log("locationName: " + locationName);
  
      locationModel.aggregate(
          [
             { $unwind:"$locations"}
            ,{ $project:{_id:0,locations:1} }
            ,{ $match:{"locations.name": locationName}}
         ]
        , function (err, res) {
          console.log('Error=' + err); 
            if (err){
              console.log('Error in fetching locations' + err);
              return (err);
            }
            console.log('Success in fetching data' + JSON.stringify(res)); 
            response.send(JSON.stringify(res));
      });
  }
  </code></pre>
  
  <p>Here is data returned by query in mongo shell. <strong>This data is NOT returned when data is fetched from node.js using mongoose.</strong></p>
  
  <pre><code>/* 0 */
  {
      "result" : [ 
          {
              "locations" : {
                  "id" : "1",
                  "parent_id" : "531",
                  "countryCode" : "IN",
                  "name" : "Noida"
              }
          }, 
          {
              "locations" : {
                  "id" : "407",
                  "parent_id" : "531",
                  "countryCode" : "IN",
                  "name" : "Greater Noida"
              }
          }
      ],
      "ok" : 1
  }.
  </code></pre>
  
  <p>And here is the original JSON document </p>
  
  <pre><code>/* 0 */
  {
      "_id" : ObjectId("548b15d700dcf350ea6a9e1e"),
      "locations" : [ 
          {
              "id" : "1",
              "parent_id" : "531",
              "countryCode" : "IN",
              "name" : "Noida"
          }, 
          {
              "id" : "2",
              "parent_id" : "531",
              "countryCode" : "IN",
              "name" : "New Delhi"
          }, 
          {
              "id" : "3",
              "parent_id" : "531",
              "countryCode" : "IN",
              "name" : "Gurgaon"
          }, 
          {
              "id" : "11",
              "parent_id" : "0",
              "countryCode" : "IN",
              "name" : "Agra"
          }, 
          {
              "id" : "12",
              "parent_id" : "0",
              "countryCode" : "IN",
              "name" : "Jaipur"
          }, 
          {
              "id" : "13",
              "parent_id" : "0",
              "countryCode" : "IN",
              "name" : "Hyderabad"
          }, 
          {
              "id" : "14",
              "parent_id" : "0",
              "countryCode" : "IN",
              "name" : "Lucknow"
          }, 
          {
              "id" : "15",
              "parent_id" : "0",
              "countryCode" : "IN",
              "name" : "Kanpur"
          }, 
          {
              "id" : "16",
              "parent_id" : "0",
              "countryCode" : "IN",
              "name" : "Lansdowne"
          }, 
          {
              "id" : "18",
              "parent_id" : "0",
              "countryCode" : "IN",
              "name" : "Bangalore"
          }, 
          {
              "id" : "19",
              "parent_id" : "0",
              "countryCode" : "IN",
              "name" : "Nainital"
          }, 
          {
              "id" : "20",
              "parent_id" : "0",
              "countryCode" : "IN",
              "name" : "Bhimtal"
          }, 
          {
              "id" : "21",
              "parent_id" : "0",
              "countryCode" : "IN",
              "name" : "Kolkata"
          }
  ]
  }
  </code></pre>