Using NoSQL MongoDB with ColdFusion
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share

Using NoSQL MongoDB with ColdFusion

  • 4,980 views
Uploaded 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......

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.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
4,980
On Slideshare
4,947
From Embeds
33
Number of Embeds
4

Actions

Shares
Downloads
51
Comments
0
Likes
4

Embeds 33

https://twitter.com 30
http://a0.twimg.com 1
http://www.pinterest.com 1
https://www.linkedin.com 1

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \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
  • 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
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Transcript

  • 1. NoSQL with ColdFusion Using MongoDB Indy Nagpal CFObjective, Melbourne, 2011
  • 2. About me
  • 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. NoSQL?
  • 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. Why NoSQL?
  • 7. Why NoSQL?✴ 100s of millions of items in a big table
  • 8. Why NoSQL?✴ 100s of millions of items in a big table✴ Dynamic data structure
  • 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. 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. 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. 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. 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. 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. 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. NoSQL DBs
  • 17. NoSQL DBs✴ Used with CF ✴ Apache CouchDB ✴ MongoDB ✴ Amazon SimpleDB✴ CF/Java Wrappers available
  • 18. What is MongoDB
  • 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. Key Difference
  • 21. Key Difference✴ Most No-SQL databases ✴ dynamic data ✴ static queries✴ MongoDB ✴ dynamic data ✴ dynamic and static queries
  • 22. Basic Concepts
  • 23. Basic Concepts✴ Database
  • 24. Basic Concepts✴ Database✴ Collections (broadly like table)
  • 25. Basic Concepts✴ Database✴ Collections (broadly like table)✴ Documents (like row)
  • 26. Basic Concepts✴ Database✴ Collections (broadly like table)✴ Documents (like row)✴ Fields (like columns)
  • 27. Basic Concepts✴ Database✴ Collections (broadly like table)✴ Documents (like row)✴ Fields (like columns)✴ Collections are indexed
  • 28. Basic Concepts✴ Database✴ Collections (broadly like table)✴ Documents (like row)✴ Fields (like columns)✴ Collections are indexed✴ Cursors (retrieve data as required)
  • 29. Concepts
  • 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. Drivers
  • 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. BSON
  • 34. BSON✴ Binary JSON format✴ Supports embedding of documents and arrays within other documents and arrays✴ Lightweight✴ Traversable✴ Efficient✴ bsonspec.org
  • 35. CF and Mongo
  • 36. CF and Mongo✴ cfmongodb (on Github) -- excellent✴ Wrapper around Java drivers✴ Most functionality encapsulated ✴ Inserts, updates, delete, find ✴ Map-reduce, Geospatial
  • 37. CF and BSON• Structs/arrays persisted as they are! people = mongo.getDBCollection(“people”) person = { “fname” : “John”, “lname” : “Doe” } people.save(person)
  • 38. Init
  • 39. InitmongoConfig = createObject( component, cfmongodb.core.MongoConfig).init(dbName="test")
  • 40. InitmongoConfig = createObject( component, cfmongodb.core.MongoConfig).init(dbName="test")mongo = createObject(component, cfmongodb.core.Mongo).init(mongoConfig)
  • 41. InitmongoConfig = createObject( component, cfmongodb.core.MongoConfig).init(dbName="test")mongo = createObject(component, cfmongodb.core.Mongo).init(mongoConfig)people = mongo.getDBCollection(people)
  • 42. Add Data
  • 43. Add Data// create some datanewPeople = []
  • 44. Add Data// create some datanewPeople = []arrayAppend(newPeople, {‘fname’: ‘John’, ‘email’ : ‘john@doe.com’})
  • 45. Add Data// create some datanewPeople = []arrayAppend(newPeople, {‘fname’: ‘John’, ‘email’ : ‘john@doe.com’})arrayAppend(newPeople, {‘fname’: ‘Jane’, ‘lname’ : ‘Doe’})
  • 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. Find / Update
  • 48. Find / Updateperson = people.query().$eq("fname", "Jane").find()
  • 49. Find / Updateperson = people.query().$eq("fname", "Jane").find()// update a recordperson[“email”] = “jane@doe.com”person.update(person)
  • 50. Tools
  • 51. Tools✴ Terminal console✴ MongoHub (Mac)✴ MongoExplorer, MongoVision (Windows)✴ SSH Tunnel to connect✴ mongohq.com (hosted MongoDB/admin)
  • 52. MongoDB and Railo
  • 53. MongoDB and Railo✴ Railo Extension✴ Cache CF variables/data✴ Store key-value pairs ✴ cacheGet() ✴ cachePut()
  • 54. Queries and Map- reduce
  • 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. Data Modeling
  • 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. CF ORM
  • 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. Asynchronous
  • 61. Asynchronous✴ Asynchronous inserts/updates✴ Journaled✴ Capped Collections (FIFO)
  • 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. Compelling features
  • 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. When to use?
  • 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. Learning Curve
  • 68. Learning Curve✴ Syntax✴ Concepts like sharding, replication✴ Well-documented / blogged✴ Active mailing list✴ Being used in production
  • 69. So...
  • 70. So...✴ Another tool to have in one’s kit✴ Extremely useful and easy to use✴ Worth spending some time on
  • 71. Thank you! @indynagpal indy@nagpals.com http://nagpals.com/blog