Jroger
Jroger

Reputation: 265

CodeIgniter + MongoDB Update

I'm trying to use the library codeigniter-library-mongodb nested in a collection. But I am not able to do updates ...

To query I am using the following code:

getFacebookUser function ($ id ='') {
   return $ this-> mongo_db-> get_where ('users', array ('facebook.id' => $ id));
}

To insert:

createFacebookUser function ($ id ='', $ acess_token ='') {
   $user = array (
     'facebook' => array (
       'id' => $ id,
       'acess_token' => $ acess_token
     )
   );
   $ this-> mongo_db-> insert ('users', $ user);
}

I tried using the following code:

updateFacebookUser function ($ id ='', $ acess_token ='') {
    $ this-> mongo_db-> update ('users', array ('facebook.acess_token' => $ acess_token), array ('facebook.id' => $ id));
}

But I am getting the following message:

Nothing to update in Mongo collection or update is not an array

The structure I'm using is the following:

user {
     name,
     {facebook
         id,
         acess_token
     }
     {twitter
        id,
        acess_token
     }
}

Upvotes: 0

Views: 2442

Answers (1)

shelman
shelman

Reputation: 2699

It might be a typo, but it seems that you are trying to update the 'users' collection when your schema says it is called 'user'.

Upvotes: 1

Related Questions