Answer the question
In order to leave comments, you need to log in
How to get childs data in mongodb?
Hello.
Can you tell me how to get the data of attached documents?
Example:
{
"_id" : ObjectId("11b97aa654bce61356002559"),
"name" : "Category",
"childs" : [
{
"_id" : ObjectId("22b55aa654bce61356002559"),
"name" : "sub-category", // под категория
"childs" : [
{
"_id" : ObjectId("33b55aa654bce61356002559"),
"name" : "sub-sub-category", //Категория третьего уровня
"childs": ""
}
]
}
]
}
$category = Categories::findOne(['childs._id' => $id]) -> childs;
foreach ($category as $cat);
$cat['name'];
$category = Categories::findOne(['childs._id' => $id]) -> childs;
foreach ($category as $cat);
foreach ($cat as $c);
$c['name'];
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question