yii-mongo-record
Yii1 MongoDB ActiveRecord model implementation, (*1)
Features
- Native Yii1 validation
- Aggregation Framework Builder
- Aggregative inherited functions (MongoRecord::count(), MongoRecord::max(), MongoRecord::min(), MongoRecord::distinct($field) etc)
- Relations between MongoRecord classes BELONGS_TO, HAS_ONE, HAS_MANY and HAS_RELATION_WITHnew (checks for item has related element, if so returns true, another false)
- MongoDbCriteria - Clone of CDbCriteria for mongo
- MongoDataProvider - Clone of CActiveDataProvider. U can use it in all standard GridView, ListView etc...
- MongoPager - paginator
- MongoSort - sorter special for mongo
Documentation
See link: API DOCUMENTATION, (*2)
Installation
Via composer:, (*3)
require: {
"edwardstock/yii-mongo-record": "dev-master"
}
Yii configuration
'mongodb' => [
'class' => 'common.extensions.Mongo.Connection.MongoDbConnection',
'host' => 'localhost',
'user' => 'MongoUser',
'password' => 'MongoPassword',
'db' => 'Collection name',
'port' => 27017
],
If you have anonymous connection, use next config:, (*4)
'mongodb' => [
'class' => 'common.extensions.Mongo.Connection.MongoDbConnection',
'host' => 'localhost',
'db' => 'Collection name',
],
br/
For more configuration. see MongoDbConnection, (*5)
Basic example
'string'],
];
}
public function beforeSave() {
if($this->isNewRecord) {
$this->password = Enctyption::passwordHash($this->password);
}
return parent::beforeSave();
}
}
//creating new user
$user = new User();
$user->username = 'superman';
$user->password = 'myPassword';
if($user->validate()) {
$user->save();
}
//here u can use id of user by:
$userId = $user->id;
// finding user
$userId = '5644541785992b6c708b4567';
$user = User::model()->findById($userId);
//or u can use MongoId
$user = User::model()->findById(new MongoId($userId));
//deleting
$user->delete();
?>