©JoeMertz- M2C:BuildingDistributedApplications 1
• AnexampleofaNoSQL database• Isschema-less– Donotdefinetablesandcolumnsinadvance– Store newdatahoweverisneeded
• Stored asBSON• SimilartoJSON,butwitha fewmoredatatypes
– JSONisessentiallyserializedJavaScriptobjects» I.e. whatJavaScriptobjectswouldlooklikeifrepresentedasanobjectliteral
• ThereforeMongoDB essentiallystoresJavaScriptobjects– Easy tosaveaJavaScriptobject– Easy torestoreasaJavaScriptobject
©JoeMertz- M2C:BuildingDistributedApplications 2
• Browse comparisonon:– http://www.mongodb.org/display/DOCS/SQL+to+Mongo+Mapping+Chart
©JoeMertz- M2C:BuildingDistributedApplications 3
• ItisunclearwhetheritisbeneficialornottobethinkingintermsofRDBMSandmappingittoMongo.
• Myintuition:– ForgetaboutRDBMSinthiscase– JustseeMongo asasimplewaytostore,query,andretrieveJavaScriptobjects
©JoeMertz- M2C:BuildingDistributedApplications 4
• Database– Adatabaseisasetofcollections
• Collections– Acollectionisasetofdocuments
• Documents– Adocumentis(essentially)aJSONstring
©JoeMertz- M2C:BuildingDistributedApplications 5
• SaveandfindJSONdocuments– EachJSONdocument isnotrestricted tohavethesamestructure,buttheymostlydo
– Eachdocumenthas(globally) unique_id• ACollection isasetofJSONdocuments• ADatabaseis asetofJSONcollections
©JoeMertz- M2C:BuildingDistributedApplications 6
• What ispassedtomongodb:{"name":"apple","price":1.99}
• Mongodb addsinan_id:{"name":"apple","price":1.99,"_id":ObjectId("35414c4ebb264d7000000000")}
©JoeMertz- M2C:BuildingDistributedApplications 7
• Mongod – theMongoDB databaseserver– Listensbydefaultonport27017– Requests/responsesviaaMongoDB protocol
• Mongo– aMongoDB shellapplication– AJavaScript shelltointeractwithMongoDB– Candoalldatabaseoperations
• MongoDB drivers– Existformany languages– Providesalanguage-specificAPIforinteractingwithMongoDB
©JoeMertz- M2C:BuildingDistributedApplications 8
• Scan:– https://www.mongodb.com/who-uses-mongodb
©JoeMertz- M2C:BuildingDistributedApplications 9
• SQL and NoSQLDBMSseachhavetheirstrengths• Ourpurposein67-328:– Exposure:havebasicknowledgeofit– AneasywaytostoreandretrievedatainaformveryclosetoJavaScriptobjects(BSON)
©JoeMertz- M2C:BuildingDistributedApplications 10
• Browseto:https://docs.mongodb.com/manual/administration/install-community/
• Followthedownloadinstructions:–MacOS:IfoundinstallingHomeBrew andthenMongoDB tobeeasy.
• Experimentwithmongoshell:– Start:https://docs.mongodb.org/getting-started/shell/import-data/
– FollowtheirexamplethroughRemoveData
©JoeMertz- M2C:BuildingDistributedApplications 11
• Studio3Thasafreeversiontoview/editmongoDB databases
©JoeMertz- M2C:BuildingDistributedApplications 12
• Inthemongoshell,youcandirectlyinteractwiththemongod inaREPL.
• Tointeractwithmongod fromwithinanodeprogram,usethenpm modulemongodb:– npm installmongodb -- save
©JoeMertz- M2C:BuildingDistributedApplications 13
• Runmongodb• Runmongo• Runmongodb example
• YoucanfindtheAPIforthedemonstratedcollectionmethodsat:– http://mongodb.github.io/node-mongodb-native/2.2/api/Collection.html
©JoeMertz- M2C:BuildingDistributedApplications 14
• DuebyWednesday(orfirst10mininclass):– mLab Introduction
• DueNovember20– ImplementsimpleCRUDoperationsforwhatyouarepersistinginyourfinalproject.
– Haveatleastasinglewebpagefromwhichyoucanget,post,(put,)anddeletedocumentstoaMongoDBdatabase.
– Youdon'thavetodoallyourfinalprojectcollections,butyouneedtodoonecollectionofdocuments,andatleast3attributesperdocument.
©JoeMertz- M2C:BuildingDistributedApplications 15