Array query PHP + mongoDB - voting system ips

By : mrkva

can you maybe help me please? I'm making my voting system in php + mongodb, and I would like to keep the ip addresses which already voted. What would be to best way? I was thinking about doing it like this:

$ipData = array('$push' => array('ips' => $ip), '$inc' => array('votes' => 1));
$collection->update(array( '_id' => $id), $ipData);

Is this the best way to do it? How would you than compare all the elements of the ips array to see if the ip already didn't voted? The list will look like (,,

Thank you!

By : mrkva


compare the user's ip with the array of IPs using the PHP function in_array()

Use a Unique Index and a UPSERT:

By : Alix Axel

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