Sunday, November 15, 2020

Mongo DB, subdocument array queries

the requirement is to remove an array element which is a dictionary from a mongo collection record 

that is not not meeting some requirement 

db.getCollection('class').find( {"hours.0.day":{$eq:"mon-fri"}}).count()

db.getCollection('class').update( {"hours.0.day":{$eq:"mon-fri"}},{

    $pull: {

      "hours": {

        "day": "mon-fri"

      }

    }

  })

references:

https://docs.mongodb.com/manual/reference/method/db.collection.update/


No comments:

Post a Comment