More Related Content
Similar to MongoUK - PHP Development
Similar to MongoUK - PHP Development (20)
MongoUK - PHP Development
- 5. 2. Connect
$mongo =
new Mongo(‘a.example.com,b.example.com’,
array('persist' => ''));
5/24
- 6. 2. Connect
mongodb://[username:password@]host1
[:port1][,host2[:port2:],...]/db
6/24
- 7. Replica Pairs
$mongo =
new Mongo(‘a.example.com,b.example.com’,
array('persist' => ''));
7/24
- 8. Replica Pairs = Failover
Replica Pair
Master A Slave A
DC1 DC2
16GB RAM 16GB RAM
Replica Pair
Master B Slave B
DC1 DC2
8/24 16GB RAM 16GB RAM
- 10. Persistent Connections
$mongo =
new Mongo(‘a.example.com,b.example.com’,
array('persist' => 'owl'));
10/24
- 11. db.stats()
Documents 937,393,315
Collections 27,566
Indexes 45,277
Stored data 638GB
Inserts 5000-8000/s
11/24
As of 17th Jun 2010.
- 12. 3. Query
$serversCollection = $mongo->selectCollection(‘servers’);
$server = $serversCollection->findOne(array(‘os’ =>
‘windows’), array(‘_id’, ‘name’, ‘ip’));
12/24
- 13. 3. Query
$serversCollection = $mongo->selectCollection(‘servers’);
$server = $serversCollection->findOne(array(‘os’ =>
‘windows’), array(‘_id’, ‘name’, ‘ip’));
13/24
- 14. 3. Query
$serversCollection = $mongo->selectCollection(‘servers’);
$server = $serversCollection->findOne(array(‘os’ =>
‘windows’), array(‘_id’, ‘name’, ‘ip’));
14/24
- 15. Docs
www.php.net/mongo
15/24
- 16. Abstraction/Map layers
•ActiveMongo
•Doctrine
•Mango
•Vork
http://www.mongodb.org/display/DOCS/PHP+Language+Center
16/24
- 17. MongoDate
MongoDB Equivalent
new MongoDate() time()
new MongoDate(strtotime(‘now’)) time()
17/24
- 18. MongoDate
$from = new MongoDate(strtotime(‘2010-06-18 00:00:00’));
$to = new MongoDate(strtotime(‘2010-06-18 23:59:59’));
$collection->find(array(‘added’ => array('$gt' => $from,
'$lte' => $to)));
18/24
- 19. MongoId
$doc = $collection->findOne(array(‘_id’ =>
‘4b74ae0d064b35442948da4c’));
19/24
- 20. MongoId
$id = new MongoId(‘4b74ae0d064b35442948da4c’);
$doc = $collection->findOne(array(‘_id’ => $id));
20/24
- 21. MongoId & remove()
Slow(er):
$collection->remove(array(‘key1’ => 5, ‘key2’ => 6));
Fast(er):
$cursor = $collection->find(array(‘key1’ => 5, ‘key2’
=> 6));
$while ($cursor->hasNext())
{
$item = $cursor->getNext();
$key = new MongoId($cursor->key());
$collection->remove(array('_id' => $key));
}
21/24
- 22. Safe insert()
$collection->insert($doc, array(‘safe’));
22/24
- 23. Docs
www.php.net/mongo
23/24
- 24. Slides
blog.boxedice.com/mongodb
David Mytton
24/24 david@boxedice.com / @davidmytton