删除存储在MongoDB中的数据

时间:2018-04-03 15:27:12

标签: php html mongodb

我正在尝试使用ID删除存储在MongoDB中的数据,但它不起作用。单击删除按钮后,MongoDB中的数据仍然存在。

HTML

<div id="id_number">
    <label class="edit_label">Enter ID number: 
        <br>
        <input id="id" type="text" name="id" placeholder="ID Number...">
        <br>
        <input id="customer_data_button" onclick="deleteData()" name="search" type="submit" value="DELETE">
    </label>
</div>

PHP

<?php
//Connect to MongoDB
$mongoClient = new MongoClient();

//Select a database
$db = $mongoClient->ecommerce;

//Extract ID from POST data
$custID = filter_input(INPUT_POST, 'id', FILTER_SANITIZE_STRING);

//Build PHP array with remove criteria 
$remCriteria = [
    "_id" => new MongoId($custID)
];

// Delete the customer document
$returnVal = $db->customers->remove($remCriteria);

// Close the connection
$mongoClient->close();
?>

0 个答案:

没有答案