0

I have structure like this

{
    "field1": "value1",
    "field2": "value2",
    "insert": [{
        "id": "23",
        "data": "abc"
    }, {
        "id": "56",
        "data": "xyz"
    }]
}

Now I wanted to add the object into insert field and remove the object from insert field what is way to write a query that will do this in yii2

Anway Kulkarni
  • 261
  • 2
  • 11
  • you should read [How to ask questions](http://stackoverflow.com/help/how-to-ask) and show your research and efforts. And, have you tried [yii/mongodb](http://www.yiiframework.com/doc-2.0/ext-mongodb-index.html) ? – saljuama Dec 22 '15 at 11:56
  • Sorry as I am begginer on stack overflow,I tried and your mention link and able to insert the record into mongo db,also able to update the fields but unable to update the multilevel fields. – Anway Kulkarni Dec 22 '15 at 12:53
  • i'm not familiar with PHP or Yii, to be honest, but in the mongo shell [in this answer](http://stackoverflow.com/a/10523963/4207875) from another question, there is a really nice example of the syntax to do so, i hope it is of any help. – saljuama Dec 22 '15 at 13:04
  • I am able to do it from directly mongo command,I am looking for using yii2's active record for that so I ask question. – Anway Kulkarni Dec 22 '15 at 13:06
  • I've checked the ActiveQuery class api, seems the asArray() method could return the "insert" contents. I can't try myself, but, you could give a try on chaining a where() after asArray() to see if you could access the documments, pretty much like a subselect in SQL – saljuama Dec 22 '15 at 13:15
  • I'm not quite understanding what you're trying to do, sorry! Are you trying to update multiple related records from a single form? – Joe Miller Dec 23 '15 at 08:20
  • I wanted to update a nested array in document of mongodb using yii2 active record – Anway Kulkarni Dec 23 '15 at 09:45

0 Answers0