R
R
Roman2016-07-23 09:10:40
NoSQL
Roman, 2016-07-23 09:10:40

What is the correct way to use $push in PHP in MongoDB?

Data:

{
"Key" : $key,
"BlueGroup" : {
        "1469132000" : {
            "X" : 1.2,
            "Y" : 3.3,
            "Z" : 2.1
        }
},
"ManyGroups" : { * }
}

My task is to add new values ​​to the group (BlueGroup) after the old ones.
$collection -> update(
        array( 'key'            => $key ),
        array( '$push'          => array(
                  'BlueGroup'   => array(
                    time()      => array(
                        'X'     => $i->X,
                        'Y'     => $i->Y,
                        'Z'     => $i->Z
                    )
                 )
                )
        )
    );

Judging by the documentation, $push does not work for me, since the "BlueGroup" has already been created in the document. Can you please tell me how to do this command?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Philipp, 2016-09-10
@xii

BlueGroup must be an array:

{
"Key" : $key,
"BlueGroup" : [
     {
        "1469132000" : {
            "X" : 1.2,
            "Y" : 3.3,
            "Z" : 2.1
        }
     }
],
"ManyGroups" : { * }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question