MongoDB
 sql >> Cơ Sở Dữ Liệu >  >> NoSQL >> MongoDB

Php Nhập đệ quy các danh mục vào MongoDB

CHỈNH SỬA:Với tất cả dữ liệu mới, tôi hiểu rõ ràng những gì bạn đang cố gắng đạt được.

Vì vậy, tôi đã chỉnh sửa chức năng cũ của mình, đây là một chức năng mới sẽ hoạt động chặt chẽ trong mã của bạn. Hãy cho tôi biết để tôi có thể điều chỉnh nếu cần.

public function setCategories($user_id)
{
    $api = new ApiCategory($user_id);
    $cats = $api->getCategories(); // retrieves structure above

    $newCats = null;
    self::recursiveCatTree($newCats, $cats);
    $this->categories = $newCats;

    $this->save(); // save the entire array of embedded documents

    if($this->getErrors())
        var_dump($this->getErrors);

}

public static function recursiveCatTree(&$result, $parent)
{
    $children = $parent['children'];

    //we unset the children so we dont have manually set every other variable
    unset( $parent['children']);
    $result = new Category();
    $result->attributes = $parent;

    //then loop the children, if no children it wont loop
    // so it will just be an empty    array
    foreach($children as $child)
    {
       $baby = null;
       self::recursiveCatTree($baby, $child);
       $result->children[] = $baby;
    }

}



  1. Redis
  2.   
  3. MongoDB
  4.   
  5. Memcached
  6.   
  7. HBase
  8.   
  9. CouchDB
  1. Định cấu hình ghi nhật ký cho trình điều khiển Java MongoDB

  2. Cách kết nối với MongoDB từ iOS (Swift)

  3. Tại sao MongoDB không sử dụng fsync ()?

  4. Làm cách nào để chèn tệp nhị phân vào mongodb bằng javascript?

  5. Tạo Mongo ObjectId (_id) với thời gian tùy chỉnh?