I'm running the following code and it works great, if no record exists it creates a new one. What I'm trying to do is modify this query so that the 'v' field also increases +1 but I'm not having any luck. Can someone help me out?
            $result = $collection->update(
                array('k'=>md5(SITE_ID.'-'.$_SERVER['HTTP_X_FORWARDED_FOR'])),
                array('$set'=>
                    array(
                        'k'=>md5(SITE_ID.'-'.$_SERVER['HTTP_X_FORWARDED_FOR']),                                                                   'st'=>SITE_ID, 
                        'ur'=>$_GET['u'],                                                
                        'ts'=>time(),
                        'dt'=>date('Ymd'), 
                        'ur'=>$_GET['p'],
                        'v'=>1
                    ),
                    array(
                        '$inc' => array('v' => 1)
                    ),
                ),
                array('upsert'=>true)
            );
                Put both the $set and the $inc in a single object:
$result = $collection->update(
    array('k'=>md5(SITE_ID.'-'.$_SERVER['HTTP_X_FORWARDED_FOR'])),
    array(
        '$set'=> array(
                'k'=>md5(SITE_ID.'-'.$_SERVER['HTTP_X_FORWARDED_FOR']),                                                                   'st'=>SITE_ID, 
                'ur'=>$_GET['u'],                                                
                'ts'=>time(),
                'dt'=>date('Ymd'), 
                'ur'=>$_GET['p']
            ),
        '$inc' => array('v' => 1)
    ),
    array('upsert'=>true)
);
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With