无法使用PHP删除mongodb文档 [英] Unable to delete mongodb document with PHP

查看:73
本文介绍了无法使用PHP删除mongodb文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过传递mongodb ID从使用php删除mongodb数据库中的记录。代码执行正常,但它没有删除指定的文档,有没有人看到下面的代码有任何问题??



I am trying to delete a record from mongodb database using php by passing mongodb ID. The code executes fine but it's not deleting the specified document, does anyone see any problem with the code below ??

 $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');
}





我的尝试:



我尝试过Stackoverflow,但那里的人似乎对此问题不感兴趣。



What I have tried:

I have tried Stackoverflow but people there don't seem to take interest in this question.

推荐答案

postData = json_decode(file_get_contents( php:// input), true ) ;
postData = json_decode(file_get_contents("php://input"), true);


conn = new MongoClient();
conn = new MongoClient();


db =


这篇关于无法使用PHP删除mongodb文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆