Use of No-SQL databases in web applications is becoming increasingly common. In part this is because they work well with rapid application development due to their schema-less nature. And partly because they scale well in a cloud-based environment without too much effort.
MongoDB is one of the many No-SQL database technologies available today. It's schema-less nature works very well with rapid application development nature of ColdFusion. Unlike other No-SQL databases, it offers the ability run arbitrary queries against databases without having to first write map-reduce functions. It also has some other interesting features like capped collections with asynchronous write ability.
In this session, Indy takes you through some common use-cases for considering MongoDB with ColdFusion applications, contrasting it with other No-SQL databases like CouchDB. And he shares his experiences of using it with cloud-based ColdFusion applications. The aim of the session is to provide an overview of using MongoDB with ColdFusion so that you have another tool to consider when working on your next web application.
This was presented at CFObjective, Melbourne, November 17-18, 2011.
3. About me
✴ Straker Translations, New Zealand
✴ Been working with CF for a while now
✴ Cloud-based applications using Railo
✴ Love CFWheels
✴ nagpals.com/blog, @indynagpal
5. NoSQL?
✴ Different things to different people
✴ Non-Relational rather than NoSQL
✴ System for storage/retrieval of data
✴ Persistence layer is not a responsibility of a
single system
20. What is MongoDB
✴ A Document-oriented database
✴ “Humongous”
✴ Scalable, high-performance, open-source
✴ An alternative to relational databases
✴ One of the NoSQL technologies
31. Concepts
✴ New terminology
✴ Similar ideas, but not identical
✴ RDBMS - columns defined for tables
✴ NoSQL - fields defined for documents
✴ Collections are more like containers
33. Drivers
✴ Officially supported drivers
✴ Language-specific drivers (Java, Ruby, etc.)
✴ Framework-specific (MongoMapper)
✴ Wrappers built on top of drivers
✴ cfmongodb built on Java drivers
✴ Unlike Apache CouchDB that uses REST
35. BSON
✴ Binary JSON format
✴ Supports embedding of documents and
arrays within other documents and arrays
✴ Lightweight
✴ Traversable
✴ Efficient
✴ bsonspec.org
37. CF and Mongo
✴ cfmongodb (on Github) -- excellent
✴ Wrapper around Java drivers
✴ Most functionality encapsulated
✴ Inserts, updates, delete, find
✴ Map-reduce, Geospatial
38. CF and BSON
• Structs/arrays persisted as they are!
people = mongo.getDBCollection(“people”)
person = {
“fname” : “John”,
“lname” : “Doe”
}
people.save(person)
45. Add Data
// create some data
newPeople = []
arrayAppend(newPeople, {‘fname’: ‘John’, ‘email’ : ‘john@doe.com’})
46. Add Data
// create some data
newPeople = []
arrayAppend(newPeople, {‘fname’: ‘John’, ‘email’ : ‘john@doe.com’})
arrayAppend(newPeople, {‘fname’: ‘Jane’, ‘lname’ : ‘Doe’})
47. Add Data
// create some data
newPeople = []
arrayAppend(newPeople, {‘fname’: ‘John’, ‘email’ : ‘john@doe.com’})
arrayAppend(newPeople, {‘fname’: ‘Jane’, ‘lname’ : ‘Doe’})
// save everything at once
people.saveAll(newPeople)
56. Queries and Map-
reduce
✴ Queries - rapid development
✴ Map-reduce - advanced querying
✴ Query and Map-reduce together give
MongoDB an edge over other NoSQL
alternatives
58. Data Modeling
✴ No Joins! Scary?
✴ Embedding documents supported via ID
✴ Big mind shift
✴ ‘Fear’ of duplicate data drives design
decisions in relational db world
60. CF ORM
✴ No support in CF ORM frameworks
✴ Other language frameworks more
advanced
✴ Ruby on Rails - mongomapper
✴ Need ORM integration for wider adoption
63. Time taken to add 20,000 records with 5 words in each record
30
25
Time in Seconds
20
15
10
5
0
mysql (cfquery) filesystem (cflog) mongodb (cfmongodb)
67. When to use?
✴ Relational DBs suffice for most projects
✴ Abstraction via ORM is very useful
✴ MongoDB -- alternative/add-on
✴ Removes reliance on only one data storage
mechanism
Two application problems:\n\nApplication 1: \n100s of millions of rows being written in clustered CF app\nSingle table with fixed number of columns\nMysql works, but slows down\nNo replication\n\nApplication 2\nApplication to generate mini applications, where number of columns can differ from each mini application to mini application\nBasic analytics needed\n\n
Two application problems:\n\nApplication 1: \n100s of millions of rows being written in clustered CF app\nSingle table with fixed number of columns\nMysql works, but slows down\nNo replication\n\nApplication 2\nApplication to generate mini applications, where number of columns can differ from each mini application to mini application\nBasic analytics needed\n\n