Update collection erases all information inside
I am new to MongoDB and trying to perform my first updates.
I have my users collection that is populated by an insert statement. Now,
I want to add or insert the field authCode with some data into a specific
user.
My problem is that when I perform the following function the whole user
data becomes replaced by the information in that update statement. My
understanding is that by using upsert I would insert or update a users
collection. given that the user already exist I expect just the authCode
field to be created or updated.
Could anyone point out what am i doing wrong?
public function addAuthCode( array $userId, $code ) {
$user = $this->db()->user;
$user->update(
$userId,
array( 'authCode' => $code ),
array( 'upsert' => true, 'safe' => true )
);
}
No comments:
Post a Comment