filtering document in mongoose based on id and one specific property

Asked By: Anonymous

just stuck on how to filter the below document on the basis of user_id and popupsArray.isSeen = true.

enter image description here

I want to get the popups from popupsArray whose isSeen = FALSE


Solution

Answered By: Anonymous

Welcome to SO. We do recommend not to post image, instead of it, you need to post your code in snippets. You can simply use the $filter in aggregation

db.collection.aggregate([
  {
    $set: {
      popupsArray: {
        "$filter": {
          "input": "$popupsArray",
          "cond": {
            $eq: [
              "$$this.isSeen",
              false
            ]
          }
        }
      }
    }
  }
])

Working Mongo playground

techinplanet staff

techinplanet staff


Windows 10 Kaufen Windows 10 Pro Office 2019 Kaufen Office 365 Lizenz Windows 10 Home Lizenz Office 2019 Home Business Kaufen windows office 365 satın al follower kaufen instagram follower kaufen porno