This document provides an overview of building an app using Perl and MongoDB. It discusses what MongoDB is and its key features. It describes the modules needed from CPAN to interface with MongoDB from Perl. It outlines the structure of a sample "Library" app to demonstrate CRUD operations on books, authors, and other entities. The document walks through building this app and interacting with MongoDB documents and collections. It provides resources to learn more about MongoDB and the MongoDB Perl API.
11. What We Will Need:
✤ MongoDB
✤ http://www.mongodb.org/downloads
Thursday, January 17, 13
12. What We Will Need:
✤ MongoDB
✤ http://www.mongodb.org/downloads
✤ CPAN Modules:
✤ https://metacpan.org/module/Mojolicious::Lite
✤ https://metacpan.org/module/MongoDB
Thursday, January 17, 13
14. Inside the MongoDB CPAN
Distribution
✤ MongoDB::MongoClient
Thursday, January 17, 13
15. Inside the MongoDB CPAN
Distribution
✤ MongoDB::MongoClient
✤ new in version 0.502.
Thursday, January 17, 13
16. Inside the MongoDB CPAN
Distribution
✤ MongoDB::MongoClient
✤ new in version 0.502.
✤ “Safe” (write-acknowledged) by default
Thursday, January 17, 13
17. Inside the MongoDB CPAN
Distribution
✤ MongoDB::MongoClient
✤ new in version 0.502.
✤ “Safe” (write-acknowledged) by default
✤ Encapsulates connection and server info
Thursday, January 17, 13
19. Inside the MongoDB CPAN
Distribution
✤ MongoDB::Database
✤ Represents a database (namespace) on the MongoDB server
Thursday, January 17, 13
20. Inside the MongoDB CPAN
Distribution
✤ MongoDB::Database
✤ Represents a database (namespace) on the MongoDB server
✤ MongoDB::Collection
✤ Represents a collection (table? kinda) in a database
Thursday, January 17, 13
21. Inside the MongoDB CPAN
Distribution
✤ MongoDB::Database
✤ Represents a database (namespace) on the MongoDB server
✤ MongoDB::Collection
✤ Represents a collection (table? kinda) in a database
✤ MongoDB::Cursor
✤ Retrieves documents (rows? kinda) from a collection
Thursday, January 17, 13
23. MongoDB Documents
✤ Documents live in Collections
Thursday, January 17, 13
24. MongoDB Documents
✤ Documents live in Collections
✤ Documents have no pre-defined schema
Thursday, January 17, 13
25. MongoDB Documents
✤ Documents live in Collections
✤ Documents have no pre-defined schema
✤ Documents have key-value pairs, like Perl hashes
Thursday, January 17, 13
26. MongoDB Documents
✤ Documents live in Collections
✤ Documents have no pre-defined schema
✤ Documents have key-value pairs, like Perl hashes
✤ Documents can have nested structure (arrays and other documents),
like Perl hashes
Thursday, January 17, 13
27. MongoDB Documents
✤ Documents live in Collections
✤ Documents have no pre-defined schema
✤ Documents have key-value pairs, like Perl hashes
✤ Documents can have nested structure (arrays and other documents),
like Perl hashes
✤ Documents look something like JSON
Thursday, January 17, 13
28. MongoDB Documents
{
'title': 'Fellowship of the Ring, The',
'author': ObjectId("507ffbb1d94ccab2da652597"),
'language': 'English',
'genre': ['fantasy', 'adventure'],
'publication': {
'name': 'George Allen & Unwin',
'location': 'London',
'date': new Date('21 July 1954'),
}
}
Thursday, January 17, 13
40. Building the Library
Remember the Genres?
{
'title': 'Fellowship of the Ring, The',
'author': ObjectId("507ffbb1d94ccab2da652597"),
'language': 'English',
'genre': ['fantasy', 'adventure'],
'publication': {
'name': 'George Allen & Unwin',
'location': 'London',
'date': new Date('21 July 1954'),
}
}
Thursday, January 17, 13
43. Where to go from here?
✤ Learn more about MongoDB:
✤ http://docs.mongodb.org/manual/
✤ Learn more about the MongoDB Perl API
✤ https://metacpan.org/module/MongoDB::Tutorial
✤ Hack on the Library demo app
✤ https://github.com/friedo/mongo-library
✤ Add/edit authors?
✤ Edit books?
Thursday, January 17, 13
44. What’s on CPAN?
✤ ODM’s (Object Document Mappers)
✤ Like ORMs but simpler
Thursday, January 17, 13
45. What’s on CPAN?
✤ Mongoose:
✤ Based on MongoMapper
from Ruby.
✤ MongoDB Docs -->
Moose objects.
Thursday, January 17, 13
46. What’s on CPAN?
✤ MongoDBI
✤ Very Perlish
✤ Moose-like Syntax
Thursday, January 17, 13
47. What’s on CPAN?
✤ MongoDB::Async
✤ Tracks upstream MongoDB Distribution
✤ Uses Coro and libev for asynchronous queries
✤ (Mostly) drop-in replacement for MongoDB driver
Thursday, January 17, 13
48. Questions
https://github.com/friedo/mongo-library
http://docs.mongodb.org/manual/
MongoDB::Tutorial
Thursday, January 17, 13