Ethan Whitt
Ethan Whitt

Reputation: 81

A better way to use find with PHP/MongoDB?

I am trying to create a function that checks to see if a user name already exists. I am still trying to get my head wrapped around MongoDB and was wonder what is the best way to approach this? I was going to do some the following (in Code Igniter):

$filter = array ('userName' => $value);
$exists = $md->find($filter);
if ($exist) {
     return TRUE
} else {
     return FALSE
}

Is there a better way?

Upvotes: 1

Views: 263

Answers (1)

sdot257
sdot257

Reputation: 10366

Looks about right, here's what I have for mine.

if ($collection->findOne(array("username" => $username)) );

return true;

Upvotes: 2

Related Questions