MongoDB PHP Driver 1.3.1 released

45 views
Skip to first unread message

Jeremy Mikola

unread,
Oct 16, 2017, 1:41:11 PM10/16/17
to mongodb-...@googlegroups.com, mongod...@googlegroups.com
The PHP team is happy to announce that version 1.3.1 of the mongodb PHP extension is now available on PECL.

Release Highlights

This release upgrades our libbson and libmongoc dependencies to 1.8.1, which fixes an issue with building the driver from some non-bash shells.

A complete list of resolved issues in this release may be found at:
https://jira.mongodb.org/secure/ReleaseNote.jspa?projectId=12484&version=18882

Documentation

Documentation is available on PHP.net:
http://php.net/set.mongodb

Feedback

We would appreciate any feedback you might have on the project:
https://jira.mongodb.org/secure/CreateIssue.jspa?pid=12484&issuetype=6

Installation

You can either download and install the source manually, or you can install the extension with:

    pecl install mongodb

or update with:

    pecl upgrade mongodb

Windows binaries are available on PECL:
http://pecl.php.net/package/mongodb

False McFakeman

unread,
Oct 18, 2017, 11:27:13 PM10/18/17
to mongodb-user
I installed a clean server with MongoDB today, and installed pear and the PHP extension.  It seems like inserts and upserts are just not working.  There is no error, I even get a write result back:

MongoDB\UpdateResult::__set_state(array( 'writeResult' => MongoDB\Driver\WriteResult::__set_state(array( )), 'isAcknowledged' => true, ))

But although the collection is created, no document within it is created.

An example of an upsert I tried:

    $actual_update_array = ['user' => 'george', 'hash'=>'2973498732498732498732'];
    
    $bulk->update(
      ['user'=>'george'],
      ['$set' => $actual_update_array, '$setOnInsert' => $actual_update_array],
      ['multi' => false, 'upsert' => true]
    );
    $m->executeBulkWrite("Whynotwork.users", $bulk);

I don't think I'm doing anything wrong, because I tried many things, including using the https://github.com/mongodb/mongo-php-library, and that also did not do any insert/upserts.

Steps I used to install:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list

sudo apt-get update
sudo apt-get install php-pear php7.0-dev mongodb
// Make the /lib/systemd/system/mongod.service service file and put the stuff in it, etc.
// Enable the extension in both php.ini's for php7.0-fpm and for the cli (I'm using Nginx and php-fpm)

Everything is loaded fine, yet the inserts/upserts don't happen, even though the collection is created.

If you'd like, I can try something and post the results, but I think something is definitely going wrong here.

Jeremy Mikola

unread,
Oct 19, 2017, 12:55:28 PM10/19/17
to mongod...@googlegroups.com
On Wed, Oct 18, 2017 at 11:27 PM, False McFakeman <falsemc...@gmail.com> wrote:
I installed a clean server with MongoDB today, and installed pear and the PHP extension.  It seems like inserts and upserts are just not working.  There is no error, I even get a write result back:

MongoDB\UpdateResult::__set_state(array( 'writeResult' => MongoDB\Driver\WriteResult::__set_state(array( )), 'isAcknowledged' => true, ))

But although the collection is created, no document within it is created.

An example of an upsert I tried:

    $actual_update_array = ['user' => 'george', 'hash'=>'2973498732498732498732'];
    
    $bulk->update(
      ['user'=>'george'],
      ['$set' => $actual_update_array, '$setOnInsert' => $actual_update_array],
      ['multi' => false, 'upsert' => true]
    );
    $m->executeBulkWrite("Whynotwork.users", $bulk);

I don't think I'm doing anything wrong, because I tried many things, including using the https://github.com/mongodb/mongo-php-library, and that also did not do any insert/upserts.

I attempted the same update operation in both the library and driver APIs and received the same BulkWriteException in both cases: "Cannot update 'user' and 'user' at the same time". This is the first time I've seen that exception, but I traced it back to a logical conflict using the same field in $set and $setOnInsert. The following Stack Overflow threads have more detail:

I can point out that $setOnInsert in your example is redundant if you're already using that same document with $set. The purpose of $setOnInsert is to set additional fields if the upsert would result in a new document insertion (on top of changes from $set). I think the server rightfully raises an error here if fields are specified for both operators, as it would be ambiguous which value should take precedence. The server could theoretically always choose to apply $set before $setOnInsert for the same field, but that detail would likely end up buried in some corner of the MongoDB manual.

That said, this doesn't explain why your code returned a write result instead of an exception, or why you observed no changes to the target collection.

I did notice that you received no output trying to print the WriteResult class with var_export() and opened PHPC-1023 to track that. Currently, the non-BSON classes in the extension only report debugging output with var_dump() (and possibly print_r()).


False McFakeman

unread,
Oct 20, 2017, 1:56:38 PM10/20/17
to mongodb-user
I only added the $setOnInsert because the regular set wasn't working.  I also tried inserts, and they didn't work either.  This was installed on a brand new Ubuntu 16.04 instance on AWS.  I'll try and see if I can reproduce it tomorrow, but I don't have much time to work on it just yet.

Jeremy Mikola

unread,
Oct 20, 2017, 2:11:32 PM10/20/17
to mongod...@googlegroups.com
On Fri, Oct 20, 2017 at 1:56 PM, False McFakeman <falsemc...@gmail.com> wrote:
I only added the $setOnInsert because the regular set wasn't working.  I also tried inserts, and they didn't work either.  This was installed on a brand new Ubuntu 16.04 instance on AWS.  I'll try and see if I can reproduce it tomorrow, but I don't have much time to work on it just yet.

When you re-test this, please use var_dump() instead of var_export() for debugging. Additionally, it'd be helpful to share a complete script that shows everything from connecting to MongoDB (feel free to censor sensitive info, such as auth credentials) to executing the write operation, and then issuing a query and not being able to read your own writes.

On the off chance you're connecting to a replica set, it'd be helpful to ensure that (a) the read is also executed against the primary server or (b) the original write uses a sufficiently high write concern such that a secondary read can still be expected to see the write.
 

--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/fd3d88b0-a39e-43c8-8a6d-fcaa5a979cbb%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages