Removing element from embedded document from MongoDB using PHP? - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Thursday, September 22, 2022

Removing element from embedded document from MongoDB using PHP?

I am trying to remove an element from embedded document of MongoDB using PHP, but it is not working at all, though I have tested the connection with findOne and it is working fine. but not working with removing the element. with '$pull' operator.

error - Call to undefined method MongoDB\Collection::update()

Query:

 $items = $collection->update(
['articleid' => 'd71c3fc3-38ac-11ed-9e97-54ee75046547','clientid' => 'A0010'],
['$pull'=>
    ['keyword' =>[
     'keyid'=>'94214'
        ]
         ] 
 ]
);

Document structure -

    {
  "_id": {
    "$oid": "62cf622c206a6fb8f9371cc6"
  },
  "articleid": "c5a58220-0309-11ed-bcd5-8c1645bdc344",
  "headline": "Bombay HC upholds order against Sebamed",
  "circulation": "6454",
  "clientid": "A0010",
  "keyword": [
    {
      "keyid": "70080",
      "keytpe": "My Company Keyword",
      "pscore": "10"
   
    },
    {
      "keyid": "70558",
      "keytpe": "My Competitor Keyword",
      "pscore": "0"
   
    }
]
} 


source https://stackoverflow.com/questions/73805284/removing-element-from-embedded-document-from-mongodb-using-php

No comments:

Post a Comment