join the prijm community

prijm is a community of people, just like you helping each other.
join them, it only takes a minute :)

Update and Delete data in Mongo DB using php

https://www.youtube.com/watch?v=3MTKZgYx3a0

Insert data in MongoDB using PHP - Part 2

I want the Data to be updated and Deleted in Mongo DB using php and the code of update & Delete should be on same page

1 0
1 reply and 0 comment

Hi @bhisha18

Sorry for late reply and not being able to upload rest of the video. If you have followed my tutorial then you are going to have a class, so start from there. As the reference here is the MongoDB update documentation. 

To update at first you need to query for the document that you want to update. For example we want to update the user whose name is "Andy", we want update it to "Mark Andy". So the code would be like this: (Add this method to the MongodbDatabase.php file)

public function update( $find, $updateable ){
    $this->db->update( $find, $updateable );
}

Now, to update the value we would call this method from any php file where you have instantiated this class, like this:

    $db->update(
        [ 'name' => 'Andy' ],
        [ 'name' => 'Mark Andy' ],
    );

Please note that i didnt tested this code, but i hope it would work, let me know if something breaks.

please login or signup to reply
post a reply
discussion resolution do more with this discussion
followed by 1 user added by 0 user save this discussion to reply later make this discussion anonymous
discussion stats
views: 984
replies: 1
favorites: 0
follower: 1
saved: 0
comments: 0