I am new to NoSQL
and MongoDB
and I am trying to $push
an array
into another field that is an array
.
I am trying to push
$dynamicInfo
into my user's profile.weightTracker
so that I can have a new array
into weightTracker
the current code push by replace but not push
the array
as a new array
every time I refresh the page / run the scrip but instead re-writes the current.
Could anyone point out what am I doing wrong?
Thanks in advance.
$dynamicInfo['currentWeight'] = '83';
$user = $this->db()->users;
// Deals with the static info that just need an update
if ( empty( $staticInfo ) == false ) {
$user->update(
array('_id' => new MongoId( $userId ) ),
array('$set' => array('profile' => $staticInfo) ),
array('upsert' => True)
);
}
// Deals with the dynamic info that needs to be inserted as array
if ( empty( $dynamicInfo ) == false ) {
//$dynamicInfo['inserted_on'] = new MongoDate();
$user->update(
array('_id' => new MongoId( $userId ) ),
array('$push' => array('profile.weightTracker' => $dynamicInfo ) ),
array('safe' => True)
);
}