免费预览已结束,剩余31页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
chris kite ,intro to mongodb,in this talk,what is mongodb? why use it? documents and collections querying javascript shell schema design,what is mongodb?,not a rdbms,mongo is not a relational database like mysql no transactions no referential integrity no joins no schema, so no columns or rows nosql,not a key-value store,mongo is not simply a key-value store like redis stores structured data rich query interface indexes map/reduce automatic sharding, gridfs, geospatial indexing, etc.,document-oriented database,records are json documents (actually bson) stored in collections no predefined schema docs in the same collection dont even need to have the same fields atomic in-place operators for contention-free updates $set, $inc, $push, $pop, etc.,mongo document,user = name: “frank furter“, occupation: “a scientist“, location: “transylvania“ ,why use mongodb?,its stupid fast!,anywhere from 2 to 10 times faster than mysql depends on which contrived benchmark youre looking at heres one i just made up:,its stupid fast!,about 50 times faster than couchdb according to /did-i-mention-mongodb-is-fast-way-to-go-mongo 2 important points: its pretty quick benchmarks are worthless unless you do them on your actual workload,its web scale!,sharding built-in, automatic, and *just works *just works guarantee applies only if you have a cluster of shard replica sets with config servers and routing servers and you define your own shard key(s) with appropriate uniformity and granularity asynchronous replication for failover and redundancy,its pretty painless,schemaless no more configuring database columns with types no more defining and managing migrations just stick your data in there, its fine nosql orms exist mostly because writing sql sucks mongos query language is basically json the mongo driver for your favorite language is really nice and officially supported handy javascript shell for the cli,its pretty painless,/* first go create the database, the table, the schema, etc. */ mysql_connect(“localhost“, “username“, “password“) or die(mysql_error(); mysql_select_db(“test“) or die(mysql_error(); $sql = “insert into users (name, age) values (janet, 23)“; mysql_query($sql); $result = mysql_query(“select * from users where age = 23“); $row = mysql_fetch_assoc($result); echo “oh, “ . $rowname . “!“; / prints “oh, janet!“,$mongo = new mongo(); / defaults to localhost with no auth $users = $mongo-test_db-users; / database and collection created implicitly $users-insert( array(name = brad, age = 25) ); $user = $users-findone( array(age = 25) ); echo “oh, “ . $user-name . “!“; / prints “oh, brad!“,mysql,mongodb,all the cool kids are doing it,/display/docs/production+deployments,documents and collections,documents and collections,documents are the records like objects in oop, or rows in rdbms collections are groups of documents usually represent a top-level class in your app heterogeneous set unlike rdbms tables, no predefined schema no foreign keys, so how do we reference other objects? dont! just embed the sub-item in the parent doc or, use a key for references and deal with the fact that you dont get integrity or joins,embedded objects,documents can embed other documents used to efficiently represent a relation for example:, name: brad majors, address: street: oak terrace, city: denton ,querying,queries,queries are documents query expression objects indicate a pattern to match db.users.find( last_name: smith ) several query objects for advanced queries db.users.find( age: $gte: 23 ) db.users.find( age: $in: 23,25 ),querying embedded objects,exact match an entire embedded object db.users.find( address: street: oak terrace, city: denton ) dot-notation for a partial match db.users.find( “address.city“: denton ),javascript shell,js shell,comes with mongodb launch it with mongo on the command-line try a simplified version at / great fit since mongo docs are basically json,live demo,if the tech demo gods allow it,schema design,i thought you said no schema?,there is no predefined schema your application creates an ad-hoc schema with the objects it creates the schema is implicit in the queries your application runs,schema design,use collections to represent the top-level classes of your application but dont just make a collection for every object type these arent like tables in an rdbms less normalization, more embedding,obligatory blog post example,a blog post has an author, some text, and many comments the comments are unique per post, but one author has many posts how would you design this in sql? lets look at how we might design it in mongo,bad schema design: references,collections for posts, authors, and comments references by manually created id,post = id: 150, author: 100, text: this is a pretty awesome post., comments: 100, 105, 112 author = id: 100, name: michael arrington posts: 150 comment = id: 105, text: whatever this sux. ,better schema design: embedding,collection for posts embed comments, author name,post = author: michael arrington, text: this is a pretty awesome post., comments: whatever this post sux., i agree, lame! ,benefits,embedded objects brought back in the same query as parent object only 1 trip to the db server required objects in the same collection are generally stored contiguously on disk spatial locality = faster if the document model matches your domain well, it can be much easier to comprehend than nasty joins,indexes,mongo supports indexes to greatly improve query performance no need to create in advance create idempotent indexes in your app with “ensure_index“,schema design limitations,no referential integrity high degree of denormalization means updating something in many places instead of on
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年杭州市丁桥医院公开招聘高层次人才备考题库有答案详解
- 2025年温州设计控股集团有限公司“3·12特招生备考题库”招聘8人的备考题库完整答案详解
- 未来五年根雕工艺品行业市场营销创新战略制定与实施分析研究报告
- 2025年宁德市部分市直医院公开招聘编外人员备考题库参考答案详解
- 未来五年网上银行市场需求变化趋势与商业创新机遇分析研究报告
- 2025年红古区人民医院招聘工作人员的备考题库及完整答案详解一套
- 2025年都兰县妇幼保健和备考题库生育服务中心招聘(编制外)公共卫生专业技术人员的备考题库含答案详解
- 2025年福州润楼运营管理有限公司公开招聘备考题库有完整答案详解
- 2025年人民日报社公开招聘工作人员64人备考题库有答案详解
- 2026年春学期语言中心课程助教招聘备考题库及完整答案详解1套
- 中储粮招聘笔试试题及答案
- 2025年山东城市服务职业学院单招职业适应性测试题库附答案
- 静脉输液不良反应临床识别与应急处理标准化流程指南
- 擦窗课件教学课件
- 红曲科普课件
- 2025-2026学年2026年九年级数学中考大题专题:二次函数的实际应用【附答案】
- 2026年苏州工业职业技术学院单招职业技能测试必刷测试卷附答案
- 商务专员面试题及答案
- 司法制度的演变与发展
- 2025年及未来5年中国视频节目播控设备行业市场运营现状及投资规划研究报告
- 医院安防预警系统构建项目分析方案
评论
0/150
提交评论