mongodb修复阵列位置

时间:2015-10-28 05:10:31

标签: php arrays mongodb codeigniter

我在下面的集合中称为类别,它具有带子文档的文档。我有数组或文档的数组位置的问题。 1.我第一次创建/插入时的类别文档。

 { 
    "_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"}
    ],
}
  1. 我在codeigniter框架中使用更新查询,如下所示

    // 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); 
    }
    
  2. 当我在shell脚本上检查我的数组时,它会重新排列。如下所示

    { 
        "_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" 
    }
    
  3. 但更新后我想要1.数组应该只有“catename”:“Baby Bathroom”在那个数组中改变。

0 个答案:

没有答案