2. MongoDB & Drupal 2/29
Plan
1. MySQL as standard.
2. Problems MySQL
3. Reply by MongoDB. Structure
4. Plus and Cons Mongo
5. Mongo and Drupal. Let's be friends
6. Work with users. Custom Module
7. Aggregation Framework
4. MongoDB & Drupal 4/29
MySQL as standard
1. It is a reliable product
2. It is easy and convenient
3. A description of 90% of all possible data
storage structures *
4. It is used by millions of people *
* rough estimates
5. MongoDB & Drupal 5/29
MySQL is SLOW
node_load – SLOW
user_load – SLOW
JOIN - SLOW
6. MongoDB & Drupal 6/29
MySQL - hard structuring
The choice between
a set of tables or
columns empty
1. Slow selection
2. Waste of memory
7. MongoDB & Drupal 7/29
Reply by MongoDB
1. Very fast insert
2. No joins => Fast select
3. Power Update
10. MongoDB & Drupal 10/29
Mongo Plus
1. Flexibility
2. Scalability
3. Atomicity
4. Support for various
types of data
5. Object Query Language
6. Map/Reduce
11. MongoDB & Drupal 11/29
Mongo Minuses
1. Enough young product
2. Max object size - 4 Mb
3. Max DB size - 2 GB
4. Typing
5. No transaction
12. MongoDB & Drupal 12/29
Mongo and PHP
Installing from a Pecl rep
OR
Download the library from
Githab and make
Detailed documentation on PHP.net and living
examples in the test folder inside the library
18. MongoDB & Drupal 18/29
Description task
Each user can be:
- name
- surname
- gender
- post
- any number of addresses
- Friends List
First and last name - required
Another fields - optional
22. MongoDB & Drupal 22/29
hook_user_update
function dc_mongodb_user_user_update(&$edit, $account, $category)
{
$keys = array('uid' => (int) $account->uid);
//Get user data from mongodb
$data = dc_mongodb_select_one('users', $keys);
$userOldName = $data['profile']['first_name'] ;
//Set update data
$data['uid'] = (int) $account->uid;
$data['profile']['first_name'] = $edit['first_name'];
//Update user collection
dc_mongodb_update('users', $keys, $data);
if ($userOldName != $edit['first_name']) {
dc_mongodb_update('users', array('friends.uid' => $data['uid'] ),
array('$set' => array('friends.$.name' => $edit['first_name'])), FALSE);
}
}
23. MongoDB & Drupal 23/29
Aggregation Framework
1. Means to calculate aggregated values
without having to use map-reduce
2. Provides similar functionality to GROUP
BY and related SQL operators
3. Add computed fields
4. Create new virtual sub-objects
5. Extract sub-fields into the top-level of
results