title: Mongodb lookup and get output flat tree structure?
body: <p>I have two collections points collection and users collection here i want to do aggregation based on userid.</p>
  
  <p>here i am trying aggregation and everything is working fine but i need to modify result </p>
  
  <pre><code>db.points.aggregate([ 
       $match: {
        store: "001",
        date: {$lte: ISODate("2017-11-10T08:15:39.736Z"), $gte: ISODate("2017-11-10T08:15:39.736Z")}
      },
  
      {
      $lookup: {
        from: "users",
        localField: "userid",
        foreignField: "_id",
        as: "user"
      }
    },
  
     {
  
         $project: 
  
         {
  
  
         _id:0,
         "userdata.purchasedetails.purchaseid" : 1,
         "userdata.purchasedetails.data" : 1,
         usermobinumber: { "$arrayElemAt": [ "$user.mobinumber", 0 ] }
  
  
  
      }}  
  </code></pre>
  
  <p>Data stored like this</p>
  
  <pre><code>{
      "userpoint": "2",
      "date":ISODate("2017-11-10T08:15:39.736Z"),
      "store":"001",
      "userid":[
      objectID("5a7565ug8945rt67"),
      objectID("8a35553d3446rt78")
      ],
      "userdata":{
          "profile":[],
          "purchasedetails":
          [{
                  "purchaseid":"dj04944",
                  "data":"awe"
  
          }]
      }
  }
  </code></pre>
  
  <p>getting result like this :</p>
  
  <pre><code>{
  "usermobinumber":"9611",
  "userdata":{
          "purchasedetails":
          [{
                  "purchaseid":"dj04944",
                  "data":"awe"
  
          }]
  }
  </code></pre>
  
  <p>my expecting result:</p>
  
  <p>I dont want tree structure output i need like this</p>
  
  <pre><code>{
   "usermobinumber":"9611",
   "purchaseid":"dj04944",
   "data":"awe"
   }
  </code></pre>
  
  <p>how can i do this help me out</p>