0
我想通过传递mongodb ID使用php从mongodb数据库删除记录。该代码执行得很好,但它不是删除指定的文档,有没有人看到下面的代码有任何问题?无法删除MongoDb文档与Php
$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');
}
它应该是'_id'而不是'id' =>'$ emp = array('_ id'=> new MongoID($ postData ['$ id']),true);'? –
也尝试过 – aliencity