1

I have a structure of MongoDB that looks like this:

Object_id {
    workflow {
        tree_id {
            other_ids {...}
            other_ids {...}
            other_ids {...}
            subscribers {
                subscriber_id {
                    email : value
                    }
                }
            }
        }
    }
}

It can be clearly seen on this screen:

My MongoDB structure

I want to add an another field, for example name : last_name, under the email : value. I tried it by using this code:

Model::where('_id', '5adde78993def907b71ce503')->push(array('workflow.5ace115a93def953d254b502.subscribers.5ad09c2993def90a2c59fa59' => ['test' => 'testvalue']));

However, this code doesn't work. It shows me an error saying:

The field 'workflow.5ace115a93def953d254b502.subscribers.5ad09c2993def90a2c59fa59' must be an array but is of type object in document {_id: ObjectId('5adde78993def907b71ce503')}

Updating with ['upsert' => true] also doesn't work, because this method removes my collection and adds data. How can I add something to this array?

2 Answers2

0

Structure shown by you does not have any array in it. All are document or sub documents. you can not perform array operation on non array objects. To treat Subscriber_id as an array , it should be something like this

subscriber_id [{ email : value }]

0

Model::where('_id', '5adde78993def907b71ce503')->push('workflow.5ace115a93def953d254b502.subscribers.5ad09c2993def90a2c59fa59' => ['test' => 'testvalue']);

please try this.

Hector Mejia
  • 11
  • 1
  • 3