0

I have collection, contain an array of objects and I want to delete one object by filter inside this array example:

"ProductsImages" : [
    {
        "_id" : ObjectId("5c6fc524c324ac0e7497b6c0"), 
        "Namefile" : "Bild-4.png", 
        "Urls" : "https://fares.blob.core.windows.net/fares2/Bild-4.png"
    }, 
    {
        "_id" : ObjectId("5c6fc52cc324ac0e7497b6c1"), 
        "Namefile" : "KINGSTON-BAY-704668-logo.png", 
        "Urls" : "https://fares.blob.core.windows.net/fares2/KINGSTON-BAY-704668-logo.png"
    }
],

so i want to delete first one which contain a "Namefile" : "Bild-4.png" in mongodb shell, or C# monogodb drive and thanks for your help.

ihssan
  • 87
  • 4
  • 10
  • 1
    Have a look at https://stackoverflow.com/a/15122017/195509 - it sounds like using the $pull operator is what you're looking for. For an example using the C# driver, have a look at https://stackoverflow.com/a/30145663/195509. – Alex B. Feb 23 '19 at 20:50
  • Possible duplicate of [MongoDB .Net driver 2.0 Pull (remove element)](https://stackoverflow.com/questions/30141958/mongodb-net-driver-2-0-pull-remove-element) – Alex B. Feb 24 '19 at 20:42

1 Answers1

1

Please try this update query

db.collName.update({"ProductsImages.Namefile": "Bild-4.png"},{$pull: {"ProductsImages": {"Namefile": "Bild-4.png"}}})

Note: Update the first filter condition as required

Mani
  • 1,471
  • 1
  • 13
  • 19