Pregunta

using mongodb driver i try to update in database referring _id field.

my code

function update_attributes($id, $data){
        $this->db_model->where('_id', $id);
        $this->db_model->updates = array('$set' => array($data));
        $query = $this->db_model->update('dff');
        return $query;
}

$data

$form_data = array(

                            'name' => set_value('name'), 
                            'description' => set_value('description')
                        );

$dfff = Dfff::update_attributes($this->input->post('id', TRUE), $form_data);

but it does not update the database. i get the error as

Update of data into MongoDB failed: localhost:27017: Invalid modifier specified: $set

where is the problem ?? using mongodb driver-alexbilbie

¿Fue útil?

Solución 2

[SOLVED] the data type of _id given to the update_attributes function was string where as the data type in database is int32x. therefore update was getting failed as the data types did not match. by making the data type in function also as int32x. update was successful. changed like this before:

$dfff = Dfff::update_attributes($this->input->post('id', TRUE), $form_data);

after changing datatype of id:

$dfff = Dfff::update_attributes($id, $form_data);

Otros consejos

This is an exception thrown by MongoDB server when you mix the modifier "$set" with a normal variable during the update process. This is both observed in the shell and PHP Mongo. This is due probably to the difference in behavior of update that when you use "$set" would only partially update the object and the latter (using a common field/variable) would actually overwrite the entire document object which is a functionality conflict.

src: http://ulaptech.blogspot.co.uk/2011/08/mongo-invalid-modifier-specifiedvar.html

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top