Reputation: 13
I am building a web-based inventory system and am trying to implement a delete function in the case that an item is entered in error. All of the examples I've looked at look very simple but I can't seem to get it to work.
<?php
// Start the session
session_start();
$id = $_SESSION['id'];
$mongo = new MongoClient(); // connect
$db = $mongo->test; // set db
$collection = $db->check_out; // set collection
$collection->remove(array('_id' => new MongoId($id)), true);
header('Location: main.php');
?>
I have printed out $id and seen that it does match the value stored in the collection.
Upvotes: 0
Views: 737
Reputation: 1701
Try using
$collection->remove(array('_id' => new MongoId($id)), array("justOne" => true));
justOne
- is the field to say how many element you have to delete
Upvotes: 1