我试图通过传递mongodb ID从使用php删除mongodb数据库中的记录。代码执行正常,但它没有删除指定的文档,是否有人看到下面的代码有任何问题?
$postData = json_decode(file_get_contents("php://input"), true);
$conn = new MongoClient();
$db = $conn->selectDB('employees');
$collection = new MongoCollection($db, 'employees');
$emp = array('id' => new MongoID($postData['$id']), true);
try {
$collection->remove($emp, array('justOne' => true));
}
catch (MongoCursorException $e) {
die(json_encode(array('message' => $e->getMessage())));
}
echo ('The employee has been deleted successfully');
}
答案 0 :(得分:0)
我相信,名为 MongoId 的课程存在问题。确定" id"的类型是。它必须是一样的。有关参考,请参阅delete mongodb document with php。我希望它能帮助你理解。