-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Every programmer need only two things:
- New, innovative technologies.
- Simple manual how to use them.
You can find both here. MongoDB is modern and powerful NoSQL database that are document-oriented. MongoAR on the other hand is effective tool how to work with records stored there. Last, but no least is this Wiki
that will help you to learn how to use both powerful tools.
-
First steps - understand the basic of
MongoAR
in few seconds. - Query builder - learn how to select and fetch records from database.
To get started you have connect to MongoDB
and send active connection to ActiveRecord
class. It couldn't be simpler than...
$mongo = new MongoClient;
$mongoDB = $mongo->test;
MongoAR\ActiveRecord::setDatabase($mongoDB);
That's all. Since now MongoAR
will be able to work properly. But you now, the main advantage of Active Record pattern is that all the tables have their own model - class. In MongoAR
you are it's all about extending MongoAR\ActiveRecord
class. Imagine that you have an array of movies meta data and want to store them in Movie
table. The following code will do it in just a few lines.
/**
* Instances of this class will represent movie documents
*/
class Movie extends MongoAR\ActiveRecord
{
}
Now fill table in database with some test data...
$movies =
[
[
'title' => 'RoboCop',
'rating' => 3.5,
'tags' => [
'action',
'crime',
'sci-fi'
]
],
[
'title' => 'RoboCop',
'rating' => 3.5,
'tags' => [
'action',
'crime',
'sci-fi'
]
],
];
foreach($movies as $movie)
{
$model = new Moview($movie);
$model->save();
}