querying.simple-queries.txt 894 B

12345678910111213141516171819202122232425
  1. Title: Simple queries
  2. Author: Dariusz Górecki <darek.krk@gmail.com>
  3. ---
  4. You can use methods that you have used to with standard Yii `CActiveRecord`'s
  5. - To find only one first matched document simply call
  6. `$model = ModelClass::model()->find()`
  7. - To find document that has some arguments set call
  8. `$model = ModelClass::model()->findByAttributes(array('attributeName'=>'attributeValue', 'attribute2'=>'otherValue'))`
  9. - You can search models by theyre primary key
  10. `$model = ModelClass::model()->findByPk(new MongoID(/* ... */))`
  11. To understand PK queries refer to [Primary Keys Section][advanced.primaryKeys]
  12. - All of above methods have the 'All' version, ie: `findAll()`, `findAllByAttributes`
  13. - They may return an array of models, or models cursor, we'll cover the cursor later
  14. **This is almost the same behavior like standard Yii ActiveRecord models, refer to them for a basic idea**