-
Notifications
You must be signed in to change notification settings - Fork 52
Update using upsert #65
Comments
From your code you have already explicitly created a new document in |
I created the User object to get an export of the User array and tried calling update statically but still have the same issue |
Couldn't you do something like this:
That should work since it's using the native PHP MongoDB extension This would look for the user with the username "example," and if not found, it would simply create that user... |
Yes, that should work but I have used the native PHP MongoDB extension anyways |
CORRECTION: use I have verified that using |
Updating a document using upsert only creates a new record but when try to save the same document with an updated key value it creates a new record altogether instead of updating the existing document as it should with "upsert"
For example:
class User extends Shanty_Mongo_Document
{
protected static $_db = 'forum';
protected static $_collection = 'user';
}
Now if you want to add or update a record based ont he criteria that email exists
$usr = new User();
//set up the values for user
$usr->update(array('email' => '[email protected]', array('$set' => $usr->export()),array('upsert' => true));
the above should either create a new User document if the email does not exist or update and existing one combining the criteria and the update.
It successfully creates a new record on the first save but on the second save it creates a new record instead of updating the existing one.
The text was updated successfully, but these errors were encountered: