D
D
Danil Solovyov2019-12-05 15:05:02
Yii
Danil Solovyov, 2019-12-05 15:05:02

How to work with nested objects in MongoDB + Yii2?

I have a collection "event" with the following structure:

_id, ... 
  games: [
    {
      _id, ...
      sides: [
        {
          _id, ...
          units: [{_id, ...}, ...]
        }, ...
      ]
    }, ...
  ]
}

I'm currently learning how to work with Yii2 and mongoDB. For this collection, I made a standard MVC via CRUD and a model generator. I manually made a conclusion in kartik/grid/gridview of nested arrays of objects through ArrayDataProvider, but naturally editing does not work now and the following questions have arisen:
1. What structure of the collection will be correct and more convenient in terms of working with it, when you need to frequently change the values ​​of the fields of nested objects ( games, sides, units)?
2. With the current structure, is it possible to make queries knowing only, for example, units._id?
3. If so, what is the best way to implement this in the model, when, for example, it is necessary to change only units._id[name]?
4. What would you advise to read about mongoDB, in addition to documentation and general development manuals?
Thanks in advance for answering questions!

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