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 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()).
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.
--
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.