A
A
Alexander Sharomet2017-03-24 16:53:23
Yii
Alexander Sharomet, 2017-03-24 16:53:23

How to display subdocument data in mongodb?

Hello.
Can you tell me how to display the data of the attached document?
For example, I need to get category products:

{
    "_id" : ObjectId("11b97aa654bce41356002559"),
    "name" : "Test",
    "images" : "test.png",
    "products" : [ 
        {
            "_id" : ObjectId("00b12aa654bce41356002559"),
            "name" : "Product 0",
            "price" : "$1 000 000 000",
        }
    ]
}

In Mysql I was getting data from another table like this:
$products = Products::find() -> where(['hit' => '1']) -> limit(6) -> all();
return $this -> render('index', compact('products'));

Tried like this:
$products = Categories::find() -> where(['products.hit' => '1']) -> limit(6) -> all();

but only the category that has such a product is returned, and I need the product itself.
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2017-03-24
@sharomet

www.yiiframework.com/doc-2.0/yii-mongodb-activeque...
www.yiiframework.com/doc-2.0/yii-mongodb-activerec...
www.yiiframework.com/doc-2.0/yii-mongodb- collection...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question