There is a task to gradually move from MySQL to mongodb now, so as not to knock down the work of the site while translating only the product, while duplicating it in two databases. The question is: there are two models of Goods and Addfields in the form of saving the Good model; there are some properties of the AddFields model in Mongo;

 "_id":"5a02d9afb2d45753294debc6", "title":"Костюм женский 'Маргарита'", "slug":"goods-Kostum-zenskij-Margarita", "discription":"<p>Цвет: темно синий, светло бежевый, голубой, ментол, сиреневый, бордовый. Оттенки могут отличаться.</p>" "product_id": 2576, "addField":[ "quote":"Цвет: темно синий, светло бежевый, голубой, ментол, сиреневый, бордовый. Оттенки могут", "size1":"48-50;52-54", "shop": "0", "composition":"дайвинг", "country":"Украина", "delivery":"3-5 дней", "site":"bole-ro", "winter""0", "spring":"0", "summer":"0", "fall":"0" ] 

addField this document is formed from both the properties of the Good and Addfields . And if with the Goods I get more or less, and it’s understandable and succeeded. Then there are problems with Addfields like this: I created a Mongo entry (the Addfield structure Addfield such an 'id' , 'id_goods' , 'key_field' , 'value' )

 $product=Products::find()->where(['product_id'=>$this->id_goods])->one(); $key=$this->key_feild; $product['addFeild'][$key]=$this->value; $product->save(); parent::afterSave($insert, $changedAttributes); 

but I get the following error

Indirect modification of overloaded element of common \ models \ mongo \ Products has no effect

swears at this line

 $product['addFeild'][$key]=$this->value; 

What am I doing wrong and how is it right?

  • I understand nothing at all in PHP ... but purely intuitively: you, in the first line, id_gods with one “o”, and according to the logic of things there should be two. - Dmytryk
  • @ Dmytryk is an artifact in the spelling here, I use not exactly the code that is in the application - Sergalas
  • Didn't you think Doctrine for mongo should be used? The class that is written in yii under mongo is not very conveniently made, especially if you need attached documents. Well, this is not an answer, but an occasion for reflection .. - OlyLad
  • @OlyLad and that this can be a link for documentation - Sergalas

0