ODM in 0.8.0, can't put conditions in findFirst() or find()

$organization = Organizations::findFirst() return one object. But when I trying to have conditions inside like

$organization = Organizations::findFirst(array(array('tax_id' => $taxId)));

It just can't find anything.

Query in mongo console could get correct object:

db.organizations.findOne({tax_id: "$taxId"})


81.1k

Do you have in the database a record where the value is "$taxId" <- dollar + taxId ?



1.3k

$taxId is a number.



81.1k

Is your model in a namespace?

Can you try to perform the query just using the Mongo extension?

$mongo = new Mongo();
$collection = $mongo->selectCollection("organizations");
$cursor = $collection->find(array('tax_id' => $taxId));
$cursor->rewind();
var_dump($cursor->current());


1.3k
        $mongo = new Mongo();
        $collection = $mongo->selectCollection("organizations");
        $cursor = $collection->find(array('tax_id' => '24436573'));
        $cursor->rewind();
        var_dump($cursor->current());

Warning: Mongo::selectCollection() expects exactly 2 parameters, 1 given in xxx.php

MongoDB Support Version 1.2.9 (found in phpinfo) mongod --version >> db version v2.0.4



1.3k

The model created following the guide in ODM documentation.



81.1k

I missed the database:

<?php

$mongo = new Mongo();
$db = $mongo->selectDb("your-db-name");
$collection = $db->selectCollection("organizations");
$cursor = $collection->find(array('tax_id' => '24436573'));
$cursor->rewind();
var_dump($cursor->current());


1.3k

It could get correct record using the code.



1.3k

Found the working syntaxes:

Organizations::findFirst(array(
            'conditions' => array('tax_id' => "{$taxId}")
        ));
Organizations::find(array(
            'conditions' => array('tax_id' => "{$taxId}"),
            'limit' => 2
        ));