MongoDB模式设计介绍.ppt
《MongoDB模式设计介绍.ppt》由会员分享,可在线阅读,更多相关《MongoDB模式设计介绍.ppt(38页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、SchemaDesignBasicsRogerBrogerbAbriefhistoryofDataModelingISAMCOBOLNetworkHiearchicalRelational1970E.F.Coddintroduces1stNormalForm(1NF)1971E.F.Coddintroduces2ndand3rdNormalForm(2NF,3NF1974Codd&BoycedefineBoyce/CoddNormalForm(BCNF)2002Date,Darween,Lorentzosdefine6thNormalForm(6NF)ObjectSowhymodeldata?
2、ModelinggoalsGoals:Avoidanomalieswheninserting,updatingordeletingMinimizeredesignwhenextendingtheschemaMakethemodelinformativetousersAvoidbiastowardsaparticularstyleofquery*source:wikipediaRelationalmadenormalizeddatalooklikethisDocumentdatabasesmakenormalizeddatalooklikethisSometermsbeforeweproceed
3、RDBMSDocument DBsTableCollectionView/Row(s)JSONDocumentIndexIndexJoinEmbedding&LinkingacrossdocumentsPartitionShardPartitionKeyShardKeyRecapDesigndocumentsthatsimplymaptoyourapplicationpost=author:“roger”,date:new Date(),text:“I love J.Biebs.”,tags:“rockstar”,“puppy-love”QueryoperatorsConditionalope
4、rators:$ne,$in,$nin,$mod,$all,$size,$exists,$type,.$lt,$lte,$gt,$gte,$ne,/findpostswithanytagsdb.posts.find(tags:$exists:true)QueryoperatorsConditionaloperators:$ne,$in,$nin,$mod,$all,$size,$exists,$type,.$lt,$lte,$gt,$gte,$ne,/findpostswithanytagsdb.posts.find(tags:$exists:true)Regularexpressions:/
5、postswhereauthorstartswithkdb.posts.find(author:/r*/i)QueryoperatorsConditionaloperators:$ne,$in,$nin,$mod,$all,$size,$exists,$type,.$lt,$lte,$gt,$gte,$ne,/findpostswithanytagsdb.posts.find(tags:$exists:true)Regularexpressions:/postswhereauthorstartswithkdb.posts.find(author:/r*/i)Counting:/postswri
6、ttenbymike db.posts.find(author:“roger”).count()ExtendingtheSchemanew_comment=author:“Gretchen”,date:newDate(),text:“BiebsisToll!”new_info=$push:comments:new_comment,$inc:comments_count:1 db.posts.update(_id:“.”,new_info)_id:ObjectId(4c4ba5c0672c685e5e8aabf3),author:”roger,date:SatJul24201019:47:11G
7、MT-0700(PDT),text:I love J.Biebs.,tags:”rockstar,”puppy-love,comments_count:1,comments:author:”Gretchen,date:SatJul24201020:51:03GMT-0700(PDT),text:”BiebsisToll!ExtendingtheSchema/createindexonnesteddocuments:db.posts.ensureIndex(comments.author:1)db.posts.find(comments.author:”Gretchen”)/findlast5p
8、osts:db.posts.find().sort(date:-1).limit(5)/mostcommentedpost:db.posts.find().sort(comments_count:-1).limit(1)Whensorting,checkifyouneedanindexExtendingtheSchemaSingleTableInheritancedb.shapes.find()_id:ObjectId(.),type:circle,area:3.14,radius:1_id:ObjectId(.),type:square,area:4,d:2_id:ObjectId(.),t
9、ype:rect,area:10,length:5,width:2/findshapeswhereradius0db.shapes.find(radius:$gt:0)/createindexdb.shapes.ensureIndex(radius:1)OnetoMany-EmbeddedArray/UsingArrayKeys-sliceoperatortoreturnsubsetofarray-hardtofindlatestcommentsacrossalldocumentsOnetoMany-EmbeddedArray/ArrayKeys-sliceoperatortoreturnsu
10、bsetofarray-hardtofindlatestcommentsacrossalldocuments-Embeddedtree-Singledocument-NaturalOnetoMany-EmbeddedArray/ArrayKeys-sliceoperatortoreturnsubsetofarray-hardtofindlatestcommentsacrossalldocuments-Embeddedtree-Singledocument-Natural-Normalized(2collections)-mostflexible-morequeriesMany-ManyExam
11、ple:-Productcanbeinmanycategories-CategorycanhavemanyproductsProducts-product_idCategory-category_idProd_Categories-id-product_id-category_idproducts:_id:ObjectId(4c4ca23933fb5941681b912e),name:SumatraDarkRoast,category_ids:ObjectId(4c4ca25433fb5941681b912f),ObjectId(4c4ca25433fb5941681b92af”ManyMan
12、yproducts:_id:ObjectId(4c4ca23933fb5941681b912e),name:SumatraDarkRoast,category_ids:ObjectId(4c4ca25433fb5941681b912f),ObjectId(4c4ca25433fb5941681b92af”categories:_id:ObjectId(4c4ca25433fb5941681b912f),name:Indonesia,product_ids:ObjectId(4c4ca23933fb5941681b912e),ObjectId(4c4ca30433fb5941681b9130),
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- MongoDB 模式 设计 介绍
限制150内