For save data from form to MongoDB database i'm using this code.
if (isset($_POST))
{
$m = new MongoClient();
$db = $m->abst;
$collection = $db->users;
print_r($_POST);
if($collection->find(array('user_id' => $pid)))
{
$collection->update(array('user_id'=>$pid),$_POST);
}
else
{
$document = array_merge(array('user_id'=>$pid),$_POST);
$collection->insert($document);
}
}
How can check user id exist in collection? and if user id exist in collection, data will update. Otherwise new entry saved to collection. where is the mistake?
Aucun commentaire:
Enregistrer un commentaire