简体   繁体   English

无法使用php驱动程序删除mongodb中的文档

[英]Unable to delete document in mongodb using php driver

Here is the structure of my document in mongo. 这是我在mongo中的文档结构。

{
"_id": {
    "$oid": "52c7ab89e4b079616e8e4be4"
},
"memberId": 1,
"memberName": "Hannan Shaik",
"memberEmail": "XXX@example.com",
"memberPhone": "123456"
}

PHP Code to remove this record is PHP代码删除该记录是

$memberId=1;
$collection->remove(array('memberId' => $memberId), array("safe" => true));

This is not removing the document. 这不是删除文档。 Whereas, below statement does. 鉴于以下声明确实如此。

 $collection->remove(array('memberId' => 1), array("safe" => true));

Kindly explain as to what is the cause for this? 请解释这是什么原因?

Please note I cannot directly give the memberId value as the above statement is written in a function that is passed with a value in $memberId. 请注意,由于上面的语句是用$ memberId中的值传递的函数编写的,因此我无法直接给出memberId的值。

It was a miss to check if the $member was a number or string. 检查$ member是数字还是字符串实在是太可惜了。

The value is $member was a string. 值是$ member是一个字符串。 Hence the issue. 因此,问题。

Thanks @Sverri M. Olsen 谢谢@Sverri M.Olsen

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM