Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Using NoSQL MongoDB with ColdFusion

6,363 views

Published on

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.

Published in: Technology
  • Be the first to comment

Using NoSQL MongoDB with ColdFusion

  1. 1. NoSQL with ColdFusion Using MongoDB Indy Nagpal CFObjective, Melbourne, 2011
  2. 2. About me
  3. 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
  4. 4. NoSQL?
  5. 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
  6. 6. Why NoSQL?
  7. 7. Why NoSQL?✴ 100s of millions of items in a big table
  8. 8. Why NoSQL?✴ 100s of millions of items in a big table✴ Dynamic data structure
  9. 9. SQL NoSQL Static Data Structure Dynamic Data Structure Dynamic Query Static Query (generally) Consistency Eventual consistency Transactions Limited Transactions Difficult to distribute Distributed, fault-tolerantLimited performance under load Optimized for heavy read-write
  10. 10. SQL NoSQL Static Data Structure Dynamic Data Structure Dynamic Query Static Query (generally) Consistency Eventual consistency Transactions Limited Transactions Difficult to distribute Distributed, fault-tolerantLimited performance under load Optimized for heavy read-write
  11. 11. SQL NoSQL Static Data Structure Dynamic Data Structure Dynamic Query Static Query (generally) Consistency Eventual consistency Transactions Limited Transactions Difficult to distribute Distributed, fault-tolerantLimited performance under load Optimized for heavy read-write
  12. 12. SQL NoSQL Static Data Structure Dynamic Data Structure Dynamic Query Static Query (generally) Consistency Eventual consistency Transactions Limited Transactions Difficult to distribute Distributed, fault-tolerantLimited performance under load Optimized for heavy read-write
  13. 13. SQL NoSQL Static Data Structure Dynamic Data Structure Dynamic Query Static Query (generally) Consistency Eventual consistency Transactions Limited Transactions Difficult to distribute Distributed, fault-tolerantLimited performance under load Optimized for heavy read-write
  14. 14. SQL NoSQL Static Data Structure Dynamic Data Structure Dynamic Query Static Query (generally) Consistency Eventual consistency Transactions Limited Transactions Difficult to distribute Distributed, fault-tolerantLimited performance under load Optimized for heavy read-write
  15. 15. SQL NoSQL Static Data Structure Dynamic Data Structure Dynamic Query Static Query (generally) Consistency Eventual consistency Transactions Limited Transactions Difficult to distribute Distributed, fault-tolerantLimited performance under load Optimized for heavy read-write
  16. 16. NoSQL DBs
  17. 17. NoSQL DBs✴ Used with CF ✴ Apache CouchDB ✴ MongoDB ✴ Amazon SimpleDB✴ CF/Java Wrappers available
  18. 18. What is MongoDB
  19. 19. What is MongoDB✴ A Document-oriented database✴ “Humongous”✴ Scalable, high-performance, open-source✴ An alternative to relational databases✴ One of the NoSQL technologies
  20. 20. Key Difference
  21. 21. Key Difference✴ Most No-SQL databases ✴ dynamic data ✴ static queries✴ MongoDB ✴ dynamic data ✴ dynamic and static queries
  22. 22. Basic Concepts
  23. 23. Basic Concepts✴ Database
  24. 24. Basic Concepts✴ Database✴ Collections (broadly like table)
  25. 25. Basic Concepts✴ Database✴ Collections (broadly like table)✴ Documents (like row)
  26. 26. Basic Concepts✴ Database✴ Collections (broadly like table)✴ Documents (like row)✴ Fields (like columns)
  27. 27. Basic Concepts✴ Database✴ Collections (broadly like table)✴ Documents (like row)✴ Fields (like columns)✴ Collections are indexed
  28. 28. Basic Concepts✴ Database✴ Collections (broadly like table)✴ Documents (like row)✴ Fields (like columns)✴ Collections are indexed✴ Cursors (retrieve data as required)
  29. 29. Concepts
  30. 30. Concepts✴ New terminology✴ Similar ideas, but not identical✴ RDBMS - columns defined for tables✴ NoSQL - fields defined for documents✴ Collections are more like containers
  31. 31. Drivers
  32. 32. 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
  33. 33. BSON
  34. 34. BSON✴ Binary JSON format✴ Supports embedding of documents and arrays within other documents and arrays✴ Lightweight✴ Traversable✴ Efficient✴ bsonspec.org
  35. 35. CF and Mongo
  36. 36. CF and Mongo✴ cfmongodb (on Github) -- excellent✴ Wrapper around Java drivers✴ Most functionality encapsulated ✴ Inserts, updates, delete, find ✴ Map-reduce, Geospatial
  37. 37. CF and BSON• Structs/arrays persisted as they are! people = mongo.getDBCollection(“people”) person = { “fname” : “John”, “lname” : “Doe” } people.save(person)
  38. 38. Init
  39. 39. InitmongoConfig = createObject( component, cfmongodb.core.MongoConfig).init(dbName="test")
  40. 40. InitmongoConfig = createObject( component, cfmongodb.core.MongoConfig).init(dbName="test")mongo = createObject(component, cfmongodb.core.Mongo).init(mongoConfig)
  41. 41. InitmongoConfig = createObject( component, cfmongodb.core.MongoConfig).init(dbName="test")mongo = createObject(component, cfmongodb.core.Mongo).init(mongoConfig)people = mongo.getDBCollection(people)
  42. 42. Add Data
  43. 43. Add Data// create some datanewPeople = []
  44. 44. Add Data// create some datanewPeople = []arrayAppend(newPeople, {‘fname’: ‘John’, ‘email’ : ‘john@doe.com’})
  45. 45. Add Data// create some datanewPeople = []arrayAppend(newPeople, {‘fname’: ‘John’, ‘email’ : ‘john@doe.com’})arrayAppend(newPeople, {‘fname’: ‘Jane’, ‘lname’ : ‘Doe’})
  46. 46. Add Data// create some datanewPeople = []arrayAppend(newPeople, {‘fname’: ‘John’, ‘email’ : ‘john@doe.com’})arrayAppend(newPeople, {‘fname’: ‘Jane’, ‘lname’ : ‘Doe’})// save everything at oncepeople.saveAll(newPeople)
  47. 47. Find / Update
  48. 48. Find / Updateperson = people.query().$eq("fname", "Jane").find()
  49. 49. Find / Updateperson = people.query().$eq("fname", "Jane").find()// update a recordperson[“email”] = “jane@doe.com”person.update(person)
  50. 50. Tools
  51. 51. Tools✴ Terminal console✴ MongoHub (Mac)✴ MongoExplorer, MongoVision (Windows)✴ SSH Tunnel to connect✴ mongohq.com (hosted MongoDB/admin)
  52. 52. MongoDB and Railo
  53. 53. MongoDB and Railo✴ Railo Extension✴ Cache CF variables/data✴ Store key-value pairs ✴ cacheGet() ✴ cachePut()
  54. 54. Queries and Map- reduce
  55. 55. Queries and Map- reduce✴ Queries - rapid development✴ Map-reduce - advanced querying✴ Query and Map-reduce together give MongoDB an edge over other NoSQL alternatives
  56. 56. Data Modeling
  57. 57. Data Modeling✴ No Joins! Scary?✴ Embedding documents supported via ID✴ Big mind shift✴ ‘Fear’ of duplicate data drives design decisions in relational db world
  58. 58. CF ORM
  59. 59. CF ORM✴ No support in CF ORM frameworks✴ Other language frameworks more advanced ✴ Ruby on Rails - mongomapper✴ Need ORM integration for wider adoption
  60. 60. Asynchronous
  61. 61. Asynchronous✴ Asynchronous inserts/updates✴ Journaled✴ Capped Collections (FIFO)
  62. 62. Time taken to add 20,000 records with 5 words in each record 30 25 Time in Seconds 20 15 10 5 0mysql (cfquery) filesystem (cflog) mongodb (cfmongodb)
  63. 63. Compelling features
  64. 64. Compelling features✴ On-demand database and collection creation✴ Asynchronous writes✴ Replication - simple and easy✴ Large-scale data processing✴ Sharding - horizontal scaling✴ Geospatial indexes
  65. 65. When to use?
  66. 66. 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
  67. 67. Learning Curve
  68. 68. Learning Curve✴ Syntax✴ Concepts like sharding, replication✴ Well-documented / blogged✴ Active mailing list✴ Being used in production
  69. 69. So...
  70. 70. So...✴ Another tool to have in one’s kit✴ Extremely useful and easy to use✴ Worth spending some time on
  71. 71. Thank you! @indynagpal indy@nagpals.com http://nagpals.com/blog

×