I have below collection called category it has document with subdocument. I have issue with the array position of array or document. 1. category document when I created/inserted first time.
{
"_id" : ObjectId("562f655fb725bc7c0e7a55a1"),
"created" : "2015-10-27 17:21:59",
"cate" : "Kids",
"status" : "1"
"subcat" : [
{"caId" : "2309f2d7be1d9072e5d84cfae30346f4", "catename" : "Toy","updateDate" : "2015-10-28 09:37:10", "status" : 2 },
{"caId" : "8e00551b75c2410f6983920b8b81a595", "catename" : "Baby Care", "updateDate" : "2015-10-28 09:37:14", "status" : 2 },
{"caId" : "46efb60afb05f9af23271253c6ab6557" "catename" : "Hiar Care", "updateDate" : "2015-10-28 09:40:35", "status" : "1"},
{"caId" : "62b9d21376a61b4477a2ea8644d476cb" "catename" : "Baby Bath", "updateDate" : "2015-10-28 09:41:15", "status" : "2"}
],
}
I use the update query in codeigniter framework as bellow
// updated caId=>62b9d21376a61b4477a2ea8644d476cb with catename =>Baby Bathroom
function updateCaste($id,$catId, $data){
$this->mongo_db->set(array("subcat.$" => $data));
$this->mongo_db->where(array("_id" => new MongoId($religiousId),"subcat.caId" => $id));
$this->mongo_db->update(category);
}
When I check my array on shell script then its get rearrange. like below
{
"_id" : ObjectId("562f655fb725bc7c0e7a55a1"),
"subcat" : [
{"caId" : "2309f2d7be1d9072e5d84cfae30346f4", "catename" : "Toy","updateDate" : "2015-10-28 09:37:10", "status" : 2 },
{"caId" : "8e00551b75c2410f6983920b8b81a595", "catename" : "Baby Care", "updateDate" : "2015-10-28 09:37:14", "status" : 2 },
{"caId" : "46efb60afb05f9af23271253c6ab6557" "catename" : "Hiar Care", "updateDate" : "2015-10-28 09:40:35", "status" : "1"},
{ "catename" : "Baby Bathroom", "updateDate" : "2015-10-28 09:41:15", "status" : "2","caId" : "62b9d21376a61b4477a2ea8644d476cb"}
],
"created" : "2015-10-27 17:21:59",
"cate" : "Kids",
"status" : "1"
}
but after update I want 1. array should be same only the "catename" : "Baby Bathroom" change in that array.