I did research too much for this functions. PHP documents is pretty bad about this topic. You can select values with this codes from your MongoDB.
This is basic user authentication system code part.

$manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");

$username = $data->username;
$password    = $data->password;

$filter = array('username' => $username, 'password' => $password);
$options = array();
$query = new MongoDB\Driver\Query($filter, $options);
$cursor = $manager->executeQuery("databaseName.collectionName", $query);
if(count($cursor->toArray()) == 0){
  // if query returns 0 record, user can't login.
  echo "NO";
}else {
  // else login
}

Bir Cevap Yazın

*