MongoDB + PHP: How to push item to array with a spcecific key?

Question!

In MongoDB-PHP I am using the following example code to push a new entry to the end of an array inside a collection...

$data = array(
        "domain"=>"superduperyoyo.com",
        "number"=>123,
        "week"=>5,
        "year"=>2012
);
$db->domains->save(
        array( 'someid' => $someid),
        array( '$push' => array( 'data' => $data ))
);

This returns keys like 0,1,2,3.... ie.

[someid] => somesupercoolid123
[data] => Array
    (
        [0] => Array
            (
                [domain] => superduperyoyo.com
                [number] => 123
                [week] => 5
                [year] => 2012
            )
        [1] => Array(...)
        [2] => Array(...)
    )

What I want to do is store YearWeekNumber as the key like this...

 [someid] => somesupercoolid123 
   [data] => Array
        (
            [201205123] => Array
                (
                    [domain] => superduperyoyo.com
                    [number] => 123
                    [week] => 5
                    [year] => 2012
                )
            [201206123] => Array(...)
            [201207123] => Array(...)
        )

How do you save/update the key along with the new entry? I am assuming you can't use $push. That you just use .save or .update but how do you pass the key?



Answers
$data = array(
        "domain"=


This video can help you solving your question :)
By: admin