Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-29101

how to use $elemMatch with $in operator in the match section of an update command

    XMLWordPrintable

    Details

    • Type: Question
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Duplicate
    • Affects Version/s: 3.4.2
    • Fix Version/s: None
    • Component/s: Querying
    • Labels:
      None

      Description

      how to use $elemMatch with $in operator in the match section of an update command....for reference check out the below command:
      Db.collection.update({participants:{$elemMatch:{participant:{$in :[1,4,5]}}}}, {$set:{"participants.$.removed": true}})
      Below is the document:
      {
      "_id" : ObjectId("590c24e76c8e0669334b68a5"),
      "name" : "The Group Name 2",
      "participants" : [

      { "participant" : 1, "admin" : true, "deleted_at" : null, "added_after" : null, "exited" : false, "removed" : false }

      ,

      { "participant" : 4, "admin" : false, "deleted_at" : null, "added_after" : null, "exited" : false, "removed" : false }

      ,

      { "participant" : 8, "admin" : false, "deleted_at" : null, "added_after" : null, "exited" : false, "removed" : false }

      ,

      { "participant" : 5, "admin" : false, "deleted_at" : null, "added_after" : null, "exited" : false, "removed" : false }

      ]

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: