|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64033 remove() doesn't return error when trying to delete a non-existant record
Submitted: 2013-01-21 03:25 UTC Modified: 2013-07-14 22:04 UTC
From: konstantin718 at gmail dot com Assigned:
Status: Not a bug Package: mongo (PECL)
PHP Version: Irrelevant OS: Ubuntu 12.04.1 LTS
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: konstantin718 at gmail dot com
New email:
PHP Version: OS:


 [2013-01-21 03:25 UTC] konstantin718 at gmail dot com
From manual page:

If you try to remove() a non-existent record from a collection with 'w' set to 1, remove() doesn't return an error or throw exception.

Instead it returns the array similar to this
Array ( [n] => 0 [connectionId] => 10726 [err] => [ok] => 1 ) 

So now we have to check if [n] is greater than 0 to actually know if remove() succeeded.

Test script:
$user_id = 'ffffffffffffffffffffffff'; // this doesn't exist in the collection.
$result = $collection->remove(array('_id' => new MongoID($user_id)), array('w' => 1));

Expected result:
Array ( [n] => 0 [connectionId] => 10726 [err] => 'some error msg' [ok] => 0 ) 

Actual result:
Array ( [n] => 0 [connectionId] => 10726 [err] => [ok] => 1 ) 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-02-24 15:23 UTC] inefedor at gmail dot com
Why should it throw an exception? There weren't any errors. Your query just evaluated in zero changed records, but it's not an error like, say in MySQL or Postgres it's not an error when you do "DELETE FROM tbl WHERE id = 123456 /*where row with id=123456 is non-existent*/".
Actually, Mongo driver here just returns what Mongo itself sent to it.
 [2013-07-14 22:04 UTC]
-Status: Open +Status: Not a bug
 [2013-07-14 22:04 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

Just like what inefedor said.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sun Jan 23 18:03:34 2022 UTC