Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Level Up! Taking your ColdFusion apps to the ne...

Level Up! Taking your ColdFusion apps to the next level with MongoDB

These are the slides from a 60-minute presentation I gave at CFCAMP in Munich, Germany on 15th October, 2013.

The blurb for the presentation was: "The new generation of NoSQL databases offer unprecedented flexibility and ease-of-use when compared to their more traditional, relational rivals. Discover how adding the powerful features of market-leading NoSQL database MongoDB to your skill set can make your ColdFusion development both more productive and more enjoyable."

The presentation was made to a group of ColdFusion developers with little to no experience of MongoDB or other NoSQL database. After a brief introduction to MongoDB, the product and company, the emphasis was on the practicalities of using MongoDB to perform the everyday CRUD (Create, Retrieve, Update, Delete) operations.

A lot of these slides will not make much sense without the talk to go with them but there you go - it was a presentation not a book reading.

As may be apparent, I am a developer not a designer.

David Waterston

October 15, 2013
Tweet

Other Decks in Programming

Transcript

  1. “Business is fantastic,” 10gen President Max Schireson told me. “We

    keep outperforming every goal that we set for ourselves and the market just feels like it’s huge.” In fact, he said, new sales people pay for themselves almost immediately upon joining the company.” – GigaOm, May, 2012
  2. { { “StaffId”: 49678, “FirstName”: “Mark”, “LastName”: “Wilson” }, {

    “StaffId”: 10234, “FirstName”: “John”, “LastName”: “Anderson” }, { “StaffId”: 76726, “FirstName”: “Tina”, “LastName”: “Lane” } }
  3. StaffId FirstName LastName 49678 Mark Wilson 10234 John Anderson 76726

    Tina Lane StaffId Hobby 49678 Swimming 49678 Reading
  4. { { “StaffId”: 49678, “FirstName”: “Mark”, “LastName”: “Wilson”, “Hobbies”: [“Swimming”,

    “Reading”] }, { “StaffId”: 10234, “FirstName”: “John”, “LastName”: “Anderson” }, { “StaffId”: 76726, “FirstName”: “Tina”, “LastName”: “Lane” } }
  5. { “StaffId”: 49678, “FirstName”: “Mark”, “LastName”: “Wilson”, “HomeAddress”: { “Street”:

    “123 High Street”, “City”: “Anytown”, “PostCode”: “AB1 2DW”, “Country”: “England” }, “Hobbies”: [“Swimming”, “Reading”] }
  6. var staffMember = { "StaffId": 49678, "FirstName": "Mark", "LastName": "Wilson",

    "HomeAddress": { "Street": "123HighStreet", "City": "Anytown", "PostCode": "AB12DW", "Country": "England" }, "Hobbies": [ "Swimming", "Reading" ] }
  7. var staffMember = { "StaffId": 49678, "FirstName": "Mark", "LastName": "Wilson",

    "HomeAddress": { "Street": "123HighStreet", "City": "Anytown", "PostCode": "AB12DW", "Country": "England" }, "Hobbies": [ "Swimming", "Reading" ] } db.Staff.insert(staffMember)
  8. db.Staff.find() { "_id" : ObjectId("525bddef0b11b9f6614c2ad6"), "StaffId" : 49678, "FirstName" :

    "Mark", "LastName" : "Wilson", "HomeAddress" : { "Street" : "123HighStreet", "City" : "Anytown", "PostCode" : "AB12DW", "Country" : "England" }, "Hobbies" : [ "Swimming", "Reading" ] } { "_id" : ObjectId("525bded60b11b9f6614c2ad7"), "StaffId" : 345678, "FirstName" : "Silvia", "LastName" : "Easton" }
  9. db.Staff.getIndexes() [ { "v" : 1, "key" : { "_id"

    : 1 }, "ns" : "test.Staff", "name" : "_id_" } ]
  10. var query = {"LastName": "Wilson"} db.Staff.find(query) var query = {"LastName":

    "Wilson", "FirstName": "Mark"} db.Staff.find(query)
  11. var query = {"LastName": "Wilson"} db.Staff.find(query) var query = {"LastName":

    "Wilson", "FirstName": "Mark"} db.Staff.find(query) var query = { $or: [ {"LastName": "Wilson" }, {"LastName": "Easton"} ] } db.Staff.find(query)
  12. var query = {"LastName": "Wilson"} db.Staff.find(query) var query = {"LastName":

    "Wilson", "FirstName": "Mark"} db.Staff.find(query) var query = { $or: [ {"LastName": "Wilson" }, {"LastName": "Easton"} ] } db.Staff.find(query) var query = { "FirstName":"Silvia", $or: [ {"LastName": "Wilson" }, {"LastName": "Easton"} ] } db.Staff.find(query)
  13. var query = {"LastName": "Wilson"} db.Staff.find(query) var query = {"LastName":

    "Wilson", "FirstName": "Mark"} db.Staff.find(query) var query = { $or: [ {"LastName": "Wilson" }, {"LastName": "Easton"} ] } db.Staff.find(query) var query = { "FirstName":"Silvia", $or: [ {"LastName": "Wilson" }, {"LastName": "Easton"} ] } db.Staff.find(query) Operators: $in, $gt, $gte, $lt, $lte, $exists... and many more
  14. { “StaffId”: 49678, “FirstName”: “Mark”, “LastName”: “Wilson”, “HomeAddress”: { “Street”:

    “123 High Street”, “City”: “Anytown”, “PostCode”: “AB1 2DW”, “Country”: “England” }, “Hobbies”: [“Swimming”, “Reading”] }
  15. var query = {"Hobbies": "Swimming"} db.Staff.find(query) var query = {"Hobbies.0":

    "Swimming"} db.Staff.find(query) var query = {"Hobbies": ["Swimming", "Reading"]} db.Staff.find(query)
  16. var query = {"Hobbies": "Swimming"} db.Staff.find(query) var query = {"Hobbies.0":

    "Swimming"} db.Staff.find(query) var query = {"Hobbies": ["Swimming", "Reading"]} db.Staff.find(query) var query = {"Hobbies": ["Swimming", "Reading", “Running”]} db.Staff.find(query)
  17. var query = {"Hobbies": "Swimming"} db.Staff.find(query) var query = {"Hobbies.0":

    "Swimming"} db.Staff.find(query) var query = {"Hobbies": ["Swimming", "Reading"]} db.Staff.find(query) var query = {"Hobbies": ["Swimming", "Reading", “Running”]} db.Staff.find(query)
  18. var query = {"Hobbies": "Swimming"} db.Staff.find(query) var query = {"Hobbies.0":

    "Swimming"} db.Staff.find(query) var query = {"Hobbies": ["Swimming", "Reading"]} db.Staff.find(query) var query = {"Hobbies": ["Swimming", "Reading", “Running”]} db.Staff.find(query)
  19. var query = {"Hobbies": "Swimming"} db.Staff.find(query) var query = {"Hobbies.0":

    "Swimming"} db.Staff.find(query) var query = {"Hobbies": ["Swimming", "Reading"]} db.Staff.find(query) var query = {"Hobbies": ["Swimming", "Reading", “Running”]} db.Staff.find(query) var query = {"Hobbies": ["Reading", "Swimming"]} db.Staff.find(query)
  20. { “StaffId”: 49678, “FirstName”: “Mark”, “LastName”: “Wilson”, “HomeAddress”: { “Street”:

    “123 High Street”, “City”: “Anytown”, “PostCode”: “AB1 2DW”, “Country”: “England” }, “Hobbies”: [“Swimming”, “Reading”] }
  21. GOTCHAS A collection need not exist to be read from

    or written to! db.staff.insert(staffMember)
  22. GOTCHAS A collection need not exist to be read from

    or written to! db.Stiff.find()
  23. GOTCHAS A field need not exist to be used in

    a query db.Staff.find({"FirstNames": "Mark"})
  24. db.Staff.find({"LastName":"Wilson"}, {"FirstName":1, "StaffId":1}) { "_id" : ObjectId("525bddef0b11b9f6614c2ad6"), "StaffId" : 49678,

    "FirstName" : "Mark" } db.Staff.find({"LastName":"Wilson"}, {"FirstName":1, "StaffId":1, "_id":0})
  25. db.Staff.find({"LastName":"Wilson"}, {"FirstName":1, "StaffId":1}) { "_id" : ObjectId("525bddef0b11b9f6614c2ad6"), "StaffId" : 49678,

    "FirstName" : "Mark" } db.Staff.find({"LastName":"Wilson"}, {"FirstName":1, "StaffId":1, "_id":0})
  26. db.Staff.find({"LastName":"Wilson"}, {"FirstName":1, "StaffId":1}) { "_id" : ObjectId("525bddef0b11b9f6614c2ad6"), "StaffId" : 49678,

    "FirstName" : "Mark" } db.Staff.find({"LastName":"Wilson"}, {"FirstName":1, "StaffId":1, "_id":0}) { "StaffId" : 49678, "FirstName" : "Mark" }
  27. db.Staff.update({"LastName": "Easton"}, {“FirstName”: “Susan”}) { "_id" : ObjectId("525bded60b11b9f6614c2ad7"), "FirstName" :

    "Susan" } db.Staff.update({"FirstName": "Susan"}, {$set: {"LastName": "Easton"}}) db.Staff.update({"FirstName": "Susanne"}, {$set: {"LastName": "Easton"}})
  28. db.Staff.update({"LastName": "Easton"}, {“FirstName”: “Susan”}) { "_id" : ObjectId("525bded60b11b9f6614c2ad7"), "FirstName" :

    "Susan" } db.Staff.update({"FirstName": "Susan"}, {$set: {"LastName": "Easton"}}) db.Staff.update({"FirstName": "Susanne"}, {$set: {"LastName": "Easton"}}) db.Staff.update({"FirstName": "Susanne"}, {$set: {"LastName": "Easton"}}, true) { "_id" : ObjectId("525c7edb3aafe4a7fc6894eb"), "FirstName" : "Susanne", "LastName" : "Easton" }
  29. { "FirstName" : "Susan", "LastName" : "Easton", "_id" : ObjectId("525bded60b11b9f6614c2ad7")

    } { "_id" : ObjectId("525c7edb3aafe4a7fc6894eb"), "FirstName" : "Susanne", "LastName" : "Easton" }
  30. { "FirstName" : "Susan", "LastName" : "Easton", "_id" : ObjectId("525bded60b11b9f6614c2ad7")

    } { "_id" : ObjectId("525c7edb3aafe4a7fc6894eb"), "FirstName" : "Susanne", "LastName" : "Easton" } db.Staff.update({"LastName": "Easton"}, {$set: {"LastName": "Susanne"}}, false, true)
  31. <cfsavecontent variable=”StaffJSON”> { “StaffId”: 49678, “FirstName”: “Mark”, “LastName”: “Wilson”, “HomeAddress”:

    { “Street”: “123 High Street”, “City”: “Anytown”, “PostCode”: “AB1 2DW”, “Country”: “England” }, “Hobbies”: [“Swimming”, “Reading”] } </cfsavecontent> <cfset Staff = DeserializeJSON(StaffJSON)>
  32. { “StaffId”: 49678, “FirstName”: “Mark”, “LastName”: “Wilson”, “HomeAddress”: { “Street”:

    “123 High Street”, “City”: “Anytown”, “PostCode”: “AB1 2DW”, “Country”: “England” }, “Hobbies”: [“Swimming”, “Reading”] }
  33. <cfset StaffMember = StructNew()> <cfset StaffMember.StaffId = 49678> <cfset StaffMember.FirstName

    = “Mark”> <cfset StaffMember.LastName = “Wilson”> <cfset Staff = mongo.getDbCollection(“Staff”)> <cfset response = Staff.save(StaffMember)>
  34. <cfscript> newStaff = []; arrayAppend (newStaff, {StaffId=49678, FirstName="Mark", LastName="Wilson"}); arrayAppend

    (newStaff, {StaffId=76726, FirstName="Tina", LastName="Lane"}); Staff = mongo.getDbCollection(“Staff”); Staff.saveAll(newStaff)> </cfscript>
  35. TAKE AWAY MongoDB has a short learning curve and, in

    some situations, may just be the best tool for the job