What is NoSQL? NoSQL Databases Explained | MongoDB
文章推薦指數: 80 %
NoSQL databases (aka "not only SQL") are non-tabular databases and store data differently than relational tables. NoSQL databases come in a variety of types ... NoSQLdatabases(aka"notonlySQL")arenon-tabulardatabasesandstoredatadifferentlythanrelationaltables.NoSQLdatabasescomeinavarietyoftypesbasedontheirdatamodel.Themaintypesaredocument,key-value,wide-column,andgraph.Theyprovideflexibleschemasandscaleeasilywithlargeamountsofdataandhighuserloads.Inthisarticle,you'lllearnwhataNoSQLdatabaseis,why(andwhen!)youshoulduseone,andhowtogetstarted.OverviewThisarticlewillcover:WhatisaNoSQLDatabase? BriefHistoryofNoSQLDatabasesNoSQLDatabaseFeaturesTypesofNoSQLDatabaseDifferencebetweenRDBMSandNoSQLWhyNoSQL?WhenshouldNoSQLbeUsed?NoSQLDatabaseMisconceptionsNoSQLQueryTutorialSummaryFAQWhatisaNoSQLdatabase?Whenpeopleusetheterm“NoSQLdatabase,”theytypicallyuseittorefertoanynon-relationaldatabase.Somesaytheterm“NoSQL”standsfor“nonSQL”whileotherssayitstandsfor“notonlySQL.”Eitherway,mostagreethatNoSQLdatabasesaredatabasesthatstoredatainaformatotherthanrelationaltables.BriefhistoryofNoSQLdatabasesNoSQLdatabasesemergedinthelate2000sasthecostofstoragedramaticallydecreased.Gonewerethedaysofneedingtocreateacomplex,difficult-to-managedatamodelinordertoavoiddataduplication.Developers(ratherthanstorage)werebecomingtheprimarycostofsoftwaredevelopment,soNoSQLdatabasesoptimizedfordeveloperproductivity.Asstoragecostsrapidlydecreased,theamountofdatathatapplicationsneededtostoreandqueryincreased.Thisdatacameinallshapesandsizes—structured,semi-structured,andpolymorphic—anddefiningtheschemainadvancebecamenearlyimpossible.NoSQLdatabasesallowdeveloperstostorehugeamountsofunstructureddata,givingthemalotofflexibility.Additionally,theAgileManifestowasrisinginpopularity,andsoftwareengineerswererethinkingthewaytheydevelopedsoftware.Theywererecognizingtheneedtorapidlyadapttochangingrequirements.Theyneededtheabilitytoiteratequicklyandmakechangesthroughouttheirsoftwarestack—allthewaydowntothedatabase.NoSQLdatabasesgavethemthisflexibility.Cloudcomputingalsoroseinpopularity,anddevelopersbeganusingpubliccloudstohosttheirapplicationsanddata.Theywantedtheabilitytodistributedataacrossmultipleserversandregionstomaketheirapplicationsresilient,toscaleoutinsteadofscaleup,andtointelligentlygeo-placetheirdata.SomeNoSQLdatabaseslikeMongoDBprovidethesecapabilities.NoSQLdatabasefeaturesEachNoSQLdatabasehasitsownuniquefeatures.Atahighlevel,manyNoSQLdatabaseshavethefollowingfeatures:FlexibleschemasHorizontalscalingFastqueriesduetothedatamodelEaseofusefordevelopersCheckoutWhataretheBenefitsofNoSQLDatabases?tolearnmoreabouteachofthefeatureslistedabove.TypesofNoSQLdatabasesOvertime,fourmajortypesofNoSQLdatabasesemerged:documentdatabases,key-valuedatabases,wide-columnstores,andgraphdatabases.DocumentdatabasesstoredataindocumentssimilartoJSON(JavaScriptObjectNotation)objects.Eachdocumentcontainspairsoffieldsandvalues.Thevaluescantypicallybeavarietyoftypesincludingthingslikestrings,numbers,booleans,arrays,orobjects.Key-valuedatabasesareasimplertypeofdatabasewhereeachitemcontainskeysandvalues.Wide-columnstoresstoredataintables,rows,anddynamiccolumns.Graphdatabasesstoredatainnodesandedges.Nodestypicallystoreinformationaboutpeople,places,andthings,whileedgesstoreinformationabouttherelationshipsbetweenthenodes.Tolearnmore,visitUnderstandingtheDifferentTypesofNoSQLDatabases.DifferencebetweenRDBMSandNoSQLdatabasesWhileavarietyofdifferencesexistbetweenrelationaldatabasemanagementsystems(RDBMS)andNoSQLdatabases,oneofthekeydifferencesisthewaythedataismodeledinthedatabase.Inthissection,we'llworkthroughanexampleofmodelingthesamedatainarelationaldatabaseandaNoSQLdatabase.Then,we'llhighlightsomeoftheotherkeydifferencesbetweenrelationaldatabasesandNoSQLdatabases.RDBMSvsNoSQL:DataModelingExampleLet'sconsideranexampleofstoringinformationaboutauserandtheirhobbies.Weneedtostoreauser'sfirstname,lastname,cellphonenumber,city,andhobbies.Inarelationaldatabase,we'dlikelycreatetwotables:oneforUsersandoneforHobbies.UsersIDfirst_namelast_namecellcity1LeslieYepp8125552344PawneeHobbiesIDuser_idhobby101scrapbooking111eatingwaffles121workingInordertoretrievealloftheinformationaboutauserandtheirhobbies,informationfromtheUserstableandHobbiestablewillneedtobejoinedtogether.ThedatamodelwedesignforaNoSQLdatabasewilldependonthetypeofNoSQLdatabasewechoose.Let'sconsiderhowtostorethesameinformationaboutauserandtheirhobbiesinadocumentdatabaselikeMongoDB.{ "_id":1, "first_name":"Leslie", "last_name":"Yepp", "cell":"8125552344", "city":"Pawnee", "hobbies":["scrapbooking","eatingwaffles","working"] }Inordertoretrievealloftheinformationaboutauserandtheirhobbies,asingledocumentcanberetrievedfromthedatabase.Nojoinsarerequired,resultinginfasterqueries.Toseeamoredetailedversionofthisdatamodelingexample,readMappingTermsandConceptsfromSQLtoMongoDB.OtherdifferencesbetweenRDBMSandrelationaldatabasesWhiletheexampleabovehighlightsthedifferencesindatamodelsbetweenrelationaldatabasesandNoSQLdatabases,manyotherimportantdifferencesexist,including:FlexibilityoftheschemaScalingtechniqueSupportfortransactionsRelianceondatatoobjectmappingTolearnmoreaboutthedifferencesbetweenrelationaldatabasesandNoSQLdatabases,visitNoSQLvsSQLDatabases.WhyNoSQL?NoSQLdatabasesareusedinnearlyeveryindustry.Usecasesrangefromthehighlycritical(e.g.,storingfinancialdataandhealthcarerecords)tothemorefunandfrivolous(e.g.,storingIoTreadingsfromasmartkittylitterbox).Inthefollowingsections,we'llexplorewhenyoushouldchoosetouseaNoSQLdatabaseandcommonmisconceptionsaboutNoSQLdatabases.WhenshouldNoSQLbeused?Whendecidingwhichdatabasetouse,decision-makerstypicallyfindoneormoreofthefollowingfactorsleadthemtoselectingaNoSQLdatabase:Fast-pacedAgiledevelopmentStorageofstructuredandsemi-structureddataHugevolumesofdataRequirementsforscale-outarchitectureModernapplicationparadigmslikemicroservicesandreal-timestreamingSeeWhentoUseNoSQLDatabasesandExploringNoSQLDatabaseExamplesformoredetailedinformationonthereasonslistedabove.NoSQLdatabasemisconceptionsOvertheyears,manymisconceptionsaboutNoSQLdatabaseshavespreadthroughoutthedevelopercommunity.Inthissection,we'lldiscusstwoofthemostcommonmisconceptions:Relationshipdataisbestsuitedforrelationaldatabases.NoSQLdatabasesdon'tsupportACIDtransactions.Tolearnmoreaboutcommonmisconceptions,readEverythingYouKnowAboutMongoDBisWrong.Misconception:relationshipdataisbestsuitedforrelationaldatabasesAcommonmisconceptionisthatNoSQLdatabasesornon-relationaldatabasesdon’tstorerelationshipdatawell.NoSQLdatabasescanstorerelationshipdata—theyjuststoreitdifferentlythanrelationaldatabasesdo.Infact,whencomparedwithrelationaldatabases,manyfindmodelingrelationshipdatainNoSQLdatabasestobeeasierthaninrelationaldatabases,becauserelateddatadoesn’thavetobesplitbetweentables.NoSQLdatamodelsallowrelateddatatobenestedwithinasingledatastructure.Misconception:NoSQLdatabasesdon'tsupportACIDtransactionsAnothercommonmisconceptionisthatNoSQLdatabasesdon'tsupportACIDtransactions.SomeNoSQLdatabaseslikeMongoDBdo,infact,supportACIDtransactions.NotethatthewaydataismodeledinNoSQLdatabasescaneliminatetheneedformulti-recordtransactionsinmanyusecases.Considertheearlierexamplewherewestoredinformationaboutauserandtheirhobbiesinbotharelationaldatabaseandadocumentdatabase.Inordertoensureinformationaboutauserandtheirhobbieswasupdatedtogetherinarelationaldatabase,we'dneedtouseatransactiontoupdaterecordsintwotables.Inordertodothesameinadocumentdatabase,wecouldupdateasingledocument—nomulti-recordtransactionrequired.NoSQLquerytutorialAvarietyofNoSQLdatabasesexist.Today,we'llbetryingMongoDB,theworld'smostpopularNoSQLdatabaseaccordingtoDB-Engines.Inthistutorial,you'llloadasampledatabaseandlearntoqueryit—allwithoutinstallinganythingonyourcomputerorpayinganything.AuthenticatetoMongoDBAtlasTheeasiestwaytogetstartedwithMongoDBisMongoDBAtlas.AtlasisMongoDB'sfullymanageddatabase-as-a-service.Atlashasaforeverfreetier,whichiswhatyou'llbeusingtoday.NavigatetoAtlas.Createanaccountifyouhaven'talready.LogintoAtlas.CreateanAtlasorganizationandproject.Formoreinformationonhowtocompletethestepsabove,visittheofficialMongoDBdocumentationoncreatinganAtlasaccount.CreateaclusterandadatabaseAclusterisaplacewhereyoucanstoreyourMongoDBdatabases.Inthissection,you'llcreateafreecluster.Onceyouhaveacluster,youcanbeginstoringdatainAtlas.YoucouldchoosetomanuallycreateadatabaseintheAtlasDataExplorer,intheMongoDBShell,inMongoDBCompass,orusingyourfavoriteprogramminglanguage.Instead,inthisexample,youwillimportAtlas'ssampledataset.CreateafreeclusterbyfollowingthestepsintheofficialMongoDBdocumentation.LoadthesampledatasetbyfollowingtheinstructionsintheofficialMongoDBdocumentation.Loadingthesampledatasetwilltakeseveralminutes.Whilewedon'tneedtothinkaboutdatabasedesignforthistutorial,notethatdatabasedesignanddatamodelingaremajorfactorsinMongoDBperformance.LearnmoreaboutbestpracticesformodelingdatainMongoDB:MongoDBSchemaDesignPatternsBlogSeriesMongoDBSchemaDesignAnti-PatternsBlogSeriesFreeMongoDBUniversityCourse:M320DataModelingQuerythedatabaseNowthatyouhavedatainyourcluster,let'squeryit!Justlikeyouhadmultiplewaystocreateadatabase,youhavemultipleoptionsforqueryingadatabase:intheAtlasDataExplorer,intheMongoDBShell,inMongoDBCompass,orusingyourfavoriteprogramminglanguage.Inthissection,you’llquerythedatabaseusingtheAtlasDataExplorer.Thisisagoodwaytogetstartedquerying,asitrequireszerosetup.NavigatetotheDataExplorer(theCollectionstab),ifyouarenotalreadythere.SeetheofficialMongoDBdocumentationforinformationonhowtonavigatetotheDataExplorer.TheleftpaneloftheDataExplorerdisplaysalistofdatabasesandcollectionsinthecurrentcluster.TherightpaneloftheDataExplorerdisplaysalistofdocumentsinthecurrentcollection.TheDataExplorerdisplaysalistofdocumentsinthelistingsAndReviewscollection.Expandthesample_mflixdatabaseintheleftpanel.Alistofthedatabase'scollectionsisdisplayed.Selectthemoviescollection.TheFindViewisdisplayedintherightpanel.Thefirsttwentydocumentsoftheresultsaredisplayed.Youarenowreadytoquerythemoviescollection.Let'squeryforthemoviePrideandPrejudice.Inthequerybar,input{title:"PrideandPrejudice"}inthequerybarandclickApply.Twodocumentswiththetitle“PrideandPrejudice”arereturned. Theresultsforqueryingformovieswiththetitle"PrideandPrejudice".Congrats!You'vesuccessfullyqueriedaNoSQLdatabase!ContinueexploringyourdataInthistutorial,weonlyscratchedthesurfaceofwhatyoucandoinMongoDBandAtlas.ContinueinteractingwithyourdatabyusingtheDataExplorertoinsertnewdocuments,editexistingdocuments,anddeletedocuments.Whenyouarereadytotrymoreadvancedqueriesthataggregateyourdata,createanaggregationpipeline.Theaggregationframeworkisanincrediblypowerfultoolforanalyzingyourdata.Tolearnmore,takethefreeMongoDBUniversityCourseM121TheMongoDBAggregationFramework.Whenyouwanttovisualizeyourdata,checkoutMongoDBCharts.ChartsistheeasiestwaytovisualizedatastoredinAtlasandAtlasDataLake.Chartsallowsyoutocreatedashboardsthatarefilledwithvisualizationsofyourdata.SummaryNoSQLdatabasesprovideavarietyofbenefitsincludingflexibledatamodels,horizontalscaling,lightningfastqueries,andeaseofusefordevelopers.NoSQLdatabasescomeinavarietyoftypesincludingdocumentdatabases,key-valuesdatabases,wide-columnstores,andgraphdatabases.MongoDBistheworld'smostpopularNoSQLdatabase.LearnmoreaboutMongoDBAtlas,andgivethefreetieratry.ExcitedtolearnmorenowthatyouhaveyourownAtlasaccount?HeadovertoMongoDBUniversitywhereyoucangetfreeonlinetrainingfromMongoDBengineersandearnaMongoDBcertification.TheQuickStartTutorialsareanothergreatplacetobegin;theywillgetyouupandrunningquicklywithyourfavoriteprogramminglanguage.FollowthistutorialwithMongoDBAtlasExperiencethebenefitsofusingMongoDB,thepremierNoSQLdatabase,onthecloud.GetStartedFree!FAQWhataretheadvantagesofNoSQL?ManyNoSQLdatabaseshavethefollowingadvantages:FlexibleschemasHorizontalscalingFastqueriesduetothedatamodelEaseofusefordevelopersCheckoutWhataretheBenefitsofNoSQLDatabases?formoredetails.Whatiseventualconsistency?Eventualconsistencyisapropertyofdistributeddatabases.Eventualconsistencyensuresthatwhenanupdateismadetothedatabase,eventuallyallnodesinthedistributeddatabasewillreflectthatupdate.WhatistheCAPtheorem?TheCAPtheoremstatesthatadistributedcomputingsystemcanprovideamaximumoftwoofthefollowingthreeproperties:consistency,availability,andpartitiontolerance.WhatisNoSQLusedfor?NoSQLdatabasesareusedinnearlyeveryindustryforavarietyofusecases.ThetypeofNoSQLdatabasedeterminesthetypicalusecase.Forexample,documentdatabaseslikeMongoDBaregeneralpurposedatabases.Key-valuedatabasesareidealforlargevolumesofdatawithsimplelookupqueries.Wide-columnstoresworkwellforusecaseswithlargeamountsofdataandpredictablequerypatterns.Graphdatabasesexcelatanalyzingandtraversingrelationshipsbetweendata.SeeUnderstandingtheDifferentTypesofNoSQLDatabasesformoreinformation.WhatisaNoSQLdatabase?ANoSQLdatabaseisadatabasethatstoresdatainaformatotherthanrelationaltables.HowdoIwriteaNoSQLquery?EachNoSQLdatabasewillhaveitsownapproachtowritingqueries.VisittheinteractiveMongoDBdocumentationtolearnmoreaboutqueryingaMongoDBdatabase.IsNoSQLhardtolearn?No,NoSQLdatabasesarenothardtolearn.Infact,manydevelopersfindmodelingdatainNoSQLdatabasestobeincrediblyintuitive.Forexample,documentsinMongoDBmaptodatastructuresinmostpopularprogramminglanguages,makingprogrammingfasterandeasier.NotethatthosewithtrainingandexperienceinrelationaldatabaseswilllikelyfaceabitofalearningcurveastheyadjusttonewwaysofmodelingdatainNoSQLdatabases.IsJSONaNoSQL?DocumentdatabasesareatypeofNoSQLdatabasethatstoredatainJSONorBSONdocuments.WhatlanguageisusedtoqueryNoSQL?NoSQLdatabasesspanavarietyoftypesandimplementations.Asaresult,NoSQLdatabasescanbequeriedusingavarietyofquerylanguagesandAPIs.MongoDB,theworld'smostpopularNoSQLdatabase,canbequeriedusingtheMongoDBQueryLanguage(MQL).DoesNoSQLhaveschema?NoSQLdatabasestypicallyhaveflexibleschemas.NotethatsomeNoSQLdatabaseslikeMongoDBalsohavesupportforschemavalidation,sodeveloperscanlockdowntheirschemasasmuchoraslittleasthey'dlikewhentheyareready.ThisarticlewaswrittenbyLaurenSchaefer,aMongoDBDeveloperAdvocate.LearnmoreaboutkeydifferencesbetweenNoSQLvsSQLDatabasesRelatedNoSQLResourcesWhatarethemaindifferencesbetweenNoSQLandSQL?WhenshouldyouuseaNoSQLdatabase?Whatarethe4differenttypesofNoSQLdatabases?NoSQLDatabasesAdvantagesNoSQLdatamodelingandschemadesignNoSQLDatabaseExamples
延伸文章資訊
- 1NoSQL入門介紹及主要類型資料庫說明 - TPIsoftware
- 將XML或JSON文件導入NoSQL概念中,採用這兩種格式作為儲存資料的方式。 - 在關聯式資料庫中主要以Table(表格)的方式儲存資料,而資料則 ...
- 2What is NoSQL? NoSQL Databases Explained | MongoDB
NoSQL databases (aka "not only SQL") are non-tabular databases and store data differently than re...
- 3NoSQL.pdf - 國立聯合大學
NoSQL興起的原因. ▫ NoSQL與關聯式資料庫的比較. ▫ NoSQL的四大類型. ▫ NoSQL的三大理論基礎. ▫ 從NoSQL到NewSQL資料庫. ▫ Redis DB與Mongo...
- 4NoSQL - 維基百科,自由的百科全書
NoSQL(最初表示Non-SQL,後來有人轉解為Not only SQL),是對不同於傳統的關聯式資料庫的資料庫管理系統的統稱。 允許部分資料使用SQL系統儲存,而其他資料允許 ...
- 5什麼是NoSQL 資料庫?
NoSQL 資料庫也稱為「非關聯式」、「NoSQL DB」或「非SQL」,以強調它們能夠以不同於關聯式(SQL) 資料庫(利用資料列和資料表) 的方式,來處理大量快速變化的非結構化 ...