L
L
LakeForest2021-05-07 02:54:03
PHP
LakeForest, 2021-05-07 02:54:03

Sokil\Mongo - returns all fields, not just the ones you need. What method to call? Or create an array yourself?

$this->collection->find()
                ->fields( ['id', 'name', 'items'])
                ->all();

Result:
{"609428bc3d145000073560ee":{"_id":{"$id":"609428bc3d145000073560ee"},"id":2,"name":"Biopj","items":[{"id":2,"name" :"cow","price":121,"img_link":null},{"id":4,"name":"co5678998o","price":990,"img_link":"qwe"},{" id":5,"name":"co22","price":990,"img_link":"qwe"}]},"6094741f2e9d451e867d2c32":{"_id":{"$id":"6094741f2e9d451e867d2c32"}, "id":1,"name":"qwertybjnjj"}}

And wanted:
{{"id":2,"name":"Biopj","items":[{"id":2,"name":"cow","price":121,"img_link":null},{ "id":4,"name":"co5678998o","price":990,"img_link":"qwe"},{"id":5,"name":"co22","price":990, "img_link":"qwe"}]},{{"id":1,"name":"qwertybjnjj"}}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question