Lets say I have this document that i'd like to update:
array(
'_id' => 123,
'entries' => array(
'4d8aae834f42e06b638d0000' => array(
'user_id' => 2,
'ts' => 'Wed, 23 Mar 2011 19: 37: 55 -0700'
)
)
)
I've got an array that i'd like to append into the entries field:
$entries = array(
'4d8aae834f42e06b638d0000' => array('user_id' => 3, 'ts' => 'Wed, 21 Mar 2011 19: 37: 55 -0700')
'4d8aae834f42e06b638d3219' => array('user_id' => 4, 'ts' => 'Wed, 22 Mar 2011 19: 37: 55 -0700')
);
The attempted query:
$updateData = array(
'$pushAll' => array(
'entries' => $entries
)
);
$db->update('journal', array('_id' => 123), $updateData, array('upsert' => true));
The above query wouldn't append the new data. Changing the modifier from $pushAll to $set obviously won't work since it'll just replace what's already in there. I've tried $addToSet and it also didn't work. I'm all out of option now.
This is how i would like the document to end up with:
array(
'_id' => 123,
'entries' => array(
'4d8aae834f42e06b638d0000' => array(
'user_id' => 2,
'ts' => 'Wed, 23 Mar 2011 19: 37: 55 -0700'
),
'4d8aae834f42e06b638d0000' => array(
'user_id' => 3,
'ts' => 'Wed, 21 Mar 2011 19: 37: 55 -0700'
),
'4d8aae834f42e06b638d3219' => array(
'user_id' => 4,
'ts' => 'Wed, 20 Mar 2011 19: 37: 55 -0700'
)
)
)
Thanks in advance.