- 5. Querying
5.1. Simple queries - 5. Querying
« Previous - 5.2. The EMongoCriteria Object
Next »
5.1. Simple queries
Author | Dariusz Górecki |
---|
You can use methods that you have used to with standard Yii CActiveRecord
's
- To find only one first matched document simply call
$model = ModelClass::model()->find()
- To find document that has some arguments set call
$model = ModelClass::model()->findByAttributes(array('attributeName'=>'attributeValue', 'attribute2'=>'otherValue'))
- You can search models by theyre primary key
$model = ModelClass::model()->findByPk(new MongoID(/* ... */))
To understand PK queries refer to [Primary Keys Section][advanced.primaryKeys]
- All of above methods have the 'All' version, ie:
findAll()
,findAllByAttributes
- They may return an array of models, or models cursor, we'll cover the cursor later
This is almost the same behavior like standard Yii ActiveRecord models, refer to them for a basic idea
- 5.1. Simple queries
5. Querying - « Previous
5. Querying - Next »
5.2. The EMongoCriteria Object