kapeels kapeels - 1 month ago 11
PHP Question

MySQL order by in mongodb findOne()

In my mongo collection, I have several records with timestamps. I want to use

findOne()
and return the oldest record with a where parameter.

If it's not possible to use
findOne()
, it's alright. I just need to return the oldest record with a where parameter.

How can this be done in MongoDB?

Answer

I had to do this.

$request =  $collection_requests->find( array( 'status' => 0 ) );
$request->sort( array( 'created' => 1 ) );
$request->limit(1);
$request->next();
$request = $request->current();  
Comments