Tuesday, 6 June 2017

$eq not working with $unwind result mongoose

i've simple schema where Events.like store objectId of user. i'd like to match a particular user in array (Events.like) and add a flag isLiked according to match.

   Events.aggregate([
    { $unwind: '$like'},
      {
          "$project":{
            //   "count" : {$size: "$like"},
            "like":1,
          "isLiked" :{ "$eq": [ "like", "593564b94642650d5b09f16b"  ] },
            //   "isLiked" : { "$cond": [{ "$eq": [ "like", "593564b94642650d5b09f16b" ] }, true, false ] } }
            }
        }
    ], function(err, list) { }

this method always give me false. see results

 "data": [
    {
      "_id": "593647ae9e10082982d3f7a2",
      "like": "593563f66d2e9f0b84553fc3",
      "isLiked": false
    },
    {
      "_id": "593643a5a1e73a2841d3cddb",
      "like": "593564b94642650d5b09f16b",
      "isLiked": false
    },
    {
      "_id": "593643a5a1e73a2841d3cddb",
      "like": "593563f66d2e9f0b84553fc3",
      "isLiked": false
    }
  ]

can anyone tell me where i'm mistaking



via shivshankar

No comments:

Post a Comment