I’m trying to use Codeigniter with codeigniter-mongodb-library/tree/v2 in order to connect with mongo and Update documents with this structure:
{
"_id" : ObjectId("50fd8bd460e958aa38000002"),
"created_at" : 1358793684,
"updated_at" : 1358793684,
"is_active" : 0,
"memberships" : [
{
}
],
"first_models" : [
[ ]
],
"second_models" : [
[ ]
],
"pages" : [
[ ]
]
}
All I want is Update some document by it’s given _id. Particularly I need to add elements inside "first_models" array. From my Codeigniter model I’m calling this:
$result = $this->mongo_db
->push(array('_id' => '50fd8bd460e958aa38000002'),array('first_models' => array('Some text here')))
->update($this->collections['sites']);
I’m getting this error when I try to Update one specific document:
Mod on _id not allowed
Seems there is some conflict with the given _id… I’m missing something and I don’t know what 🙁
I’m using Mongodb 2.2.2 with Codeigniter 2.1.3, PHP5.4 and Apache2.
I was going in wrong direction with that. Finally @Rajan points me to right solution:
You can see, using
setinsteadpush, and referencing object id withnew MongoId($id)🙂