我正在构建一个基于Web的库存系统,并试图在输入错误的项目中实现删除功能。我看过的所有示例都非常简单,但似乎无法正常工作。
<?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');
?>
我已经打印出$ id,并且看到它确实与存储在集合中的值匹配。
尝试使用
$collection->remove(array('_id' => new MongoId($id)), array("justOne" => true));
justOne
-表示您必须删除多少个元素的字段
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句