Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Fixed PHP-633: findAndModify sometimes throws exception on success

Looks like we are getting a float back from the server, which we
are accessing like a unconverted normal long
Although I cannot reproduce this, I suspect this to be the issue
  • Loading branch information...
commit fa5df71b37744ffdff808cb5fe780373524b491b 1 parent 09790a0
@bjori bjori authored derickr committed
Showing with 1 addition and 1 deletion.
  1. +1 −1  collection.c
2  collection.c
@@ -1811,7 +1811,7 @@ static int php_mongo_trigger_error_on_command_failure(zval *document TSRMLS_DC)
zval **tmpvalue;
if (zend_hash_find(Z_ARRVAL_P(document), "ok", strlen("ok") + 1, (void **) &tmpvalue) == SUCCESS) {
- if (Z_LVAL_PP(tmpvalue) < 1) {
+ if ((Z_TYPE_PP(tmpvalue) == IS_LONG && Z_LVAL_PP(tmpvalue) < 1) || (Z_TYPE_PP(tmpvalue) == IS_DOUBLE && Z_DVAL_PP(tmpvalue) < 1)) {
zval **tmp, *exception;
char *message;
long code;

5 comments on commit fa5df71


I'm debugging some odd issues in our setup and suspect this may have been the problem. Do you have an idea what circumstances might cause a float to be returned? thanks! @bjori


The original reporter was running on windows, and that is the only difference I can see - although it really shouldn't have mattered.
He has confirmed that this did fix the issue for him..
I did manage to reproduce it eventually by trying out various mongod versions on different platforms.

The code was overly protective about the specific type, so it was "wrong all along"



I am running mongodb on Debian 6.0 and I am having the same problem with the 'ok' attribute associated with a float type value.

I looked at the fix that you did on:

and the latest version of mongo-php-driver that I get using:
git clone

contains this fix. Still, when I print the result of findandmodify, the type of the attribute 'ok' remains float.

The problem could be that I install the driver using the:

sudo make install (I am on Debian 6.0)

rather than what you suggested:
php -n -dextension=modules/ path/to/script.php

but this is because I don't understand what the path/to/script.php should be, and also my php does not have -dextension option.

Here is the return from the findandmodify that I get:

array(3) { ["value"]=> array(2) { ["_id"]=> string(7) "refinid"
["key"]=> int(3) } ["lastErrorObject"]=> array(2) {
["updatedExisting"]=> bool(true) ["n"]=> int(1) } ["ok"]=> float(1)

and the query on the db is:
$result = $this->db->command(
'findAndModify' => 'counters',
'query' => array(
'_id' => 'refinid'),
'update' => array('$inc' => array('key' => 1)),
'upsert' => 1,
'new' => 1

I would be very grateful for your help.

Best regards,


Sorry I forgot to say that I got the command:
php -n -dextension=modules/ path/to/script.php



PHP has had -dextension=... option since around PHP4.3 I think, so you definitely have that option :)

Can you verify that 'make install' actually overwrite your previous version? Please run:
$ php --ri mongo | grep -i vers

It shouldn't matter that the document returns a float(1) now, we don't cast it to an integer, rather simply check if the "ok" field is either less then int(1) or less then float(1)

Please sign in to comment.
Something went wrong with that request. Please try again.