title: MongoDB Aggregation check if array contains values
body: <p>I have following documents.</p>
  
  <pre><code>{
      "_id" : ObjectId("5e9d9503853d3e2149fe6a22"),
      "Profitloss" : "PROFIT",
      "Remark" : null,
      "IsSelectedUser" : true,
      "UserList" : [ 
          ObjectId("5e9d2ba9853d3e2149fe6a07")
      ],
      "SenderId" : ObjectId("5e57a9477f8a1218849c9fc7"),
      "CreateDate" : ISODate("2020-04-20T12:26:43.725Z"),
      "ExitPrice" : 530,
      "FinalAmount" : 23160,
      "IsUpdate" : true,
      "LastModify" : ISODate("2020-04-20T12:56:23.794Z")
  },{
      "_id" : ObjectId("5e9d9503853d3e2149fe6a22"),
      "Profitloss" : "PROFIT",
      "Remark" : null,
      "IsSelectedUser" : true,
      "UserList" : [ 
          ObjectId("5e9d2ba9853d3e2149fe6a08")
          ObjectId("5e9d2ba9853d3e2149fe6a09")
      ],
      "SenderId" : ObjectId("5e57a9477f8a1218849c9fc7"),
      "CreateDate" : ISODate("2020-04-20T12:26:43.725Z"),
      "ExitPrice" : 530,
      "FinalAmount" : 23160,
      "IsUpdate" : true,
      "LastModify" : ISODate("2020-04-20T12:56:23.794Z")
  }
  </code></pre>
  
  <p>Suppose my id is "5e57a9477f8a1218849c9fc7". so while fetching documents i want all the data but if in UserList array there was my id exists then i want to add 1 fields like "IsMyStatus" : true and if not exist then "IsMyStatus" : false. so the final output will be like this.</p>
  
  <pre><code>{
      "_id" : ObjectId("5e9d9503853d3e2149fe6a22"),
      "Profitloss" : "PROFIT",
      "Remark" : null,
      "IsSelectedUser" : true,
      "UserList" : [ 
          ObjectId("5e9d2ba9853d3e2149fe6a07")
      ],
      "SenderId" : ObjectId("5e57a9477f8a1218849c9fc7"),
      "CreateDate" : ISODate("2020-04-20T12:26:43.725Z"),
      "ExitPrice" : 530,
      "FinalAmount" : 23160,
      "IsUpdate" : true,
      "LastModify" : ISODate("2020-04-20T12:56:23.794Z"),
      "IsMyStatus" : true
  
  },{
      "_id" : ObjectId("5e9d9503853d3e2149fe6a22"),
      "Profitloss" : "PROFIT",
      "Remark" : null,
      "IsSelectedUser" : true,
      "UserList" : [ 
          ObjectId("5e9d2ba9853d3e2149fe6a08")
          ObjectId("5e9d2ba9853d3e2149fe6a09")
      ],
      "SenderId" : ObjectId("5e57a9477f8a1218849c9fc7"),
      "CreateDate" : ISODate("2020-04-20T12:26:43.725Z"),
      "ExitPrice" : 530,
      "FinalAmount" : 23160,
      "IsUpdate" : true,
      "LastModify" : ISODate("2020-04-20T12:56:23.794Z"),
       "IsMyStatus" : false
  }
  </code></pre>