Chapter 1 A database for the modern web

Why are developers interested in MongoDB?

MongoDB is a database management system designed to rapidly develop web applications and internet infrastructure.

MongoDB's document format is based on JSON,a popular schema for storing arbitrary data structures.JSON is an acronym for JavaScript Object Notation.

1.1 Built for the internet

1.2 MongoDB's key features

  1. Document data model
  •  MongoDB's data model is document-oriented.
  • A JSON document needs double quotes everywhere except for numeric values.
  • MongoDB stores documents in a format called Binary JSON,or BSON.

    2.Schema Model Advantages

This lack of imposed schema confers some advantages.

  • First,your application code, and not  the database,enforces the data's structure. This can speed up initial application development when the schema is changing frequently.
  • Second,and more significantly,a schema-less model allows you to represent data with truly variable properties.

   3.Ad hoc queries

to say that a system supports ad hoc queries is to say that isn't necessary to define in advance what sorts of queries the system will accept.

   4.Indexes

Indexes in MongoDB are implemented as a B-tree data structure.WiredTiger has support for long-structured merge-trees(LSM) that's expected to be available in the MongoDB 3.2 production release.

Permitting multiple secondary indexes MongoDB allows users to optimize for a wide variety of queries.

With MongoDB,you can create up to 64 indexes per collection.The kinds of indexes supported include all the ones you'd find in an RDMBS;ascending,descending,unique,compound-key,hashed,text,and even geospatial indexes are supported.

5.Replication

MongoDB provides database replication via to topology known as a replica set.

  • Replica sets distribute data across two or more machines for redundancy and automate failover in the event of server and network outages.
  • replication is used to scale database reads.

6.Speed and durability

  • Write speed can be understood as the volume of inserts,updates, and deletes that a database can process in a given time frame.
  • Durability refers to level of assurance that these write operations have been made permanent.

In MongoDB's case ,users control the speed and durability trade-off by choosing write semantics and deciding whether to enable journaling.Journaling is enabled by default since MongoDB v2.0.

7.Scaling

The easiest way to scale most databases is to upgrade the hardware.

1.3 MongoDB's core server and tools

1.3.1 Core server

The core database server runs via an executable called mongod(mongodb.exe on Windows).The mongod server process receives commands over a network socket using a custom binary protocol.

1.3.2 JavaScript shell

1.3.3 Database drivers

The driver is the code used in an application to communicate with a MongoDB server.All drivers have functionality to query,retrive results, write data ,and run database commands.

1.3.4 Commnad-line tools

MongoDB is bundled with several command-line utilities :

  • mongodump and mongorestore ----- Standard utilities for backing up and restoring a database.mongodump saves the databases's data in its native BSON format and thus is best used for backups only;this tool has the advantage of being usable for hot backups,which can easily be restored with mongorestore.
  • mongoexport and mongoimport ---Export and import JSON,CSV, and TSV^7 data.  mongoimport can also be good for initial imports of large data sets
  • mongosniff --- A wire-sniffing tool for viewing operations sent to the database.
  • mongostat --- Similar to iostat, this utility constantly polls MongoDB and the system to provide helpful stats,including the number of operations per second(inserts,queries,updates,deletes, and so on), the amount of virtual memory allocated, and the number of connections to the server.
  • mongotop --- Similar to top, this utility polls MongoDB and shows the amount of time it spends reading and writing data in each collection.
  • mongoperf --- Helps you understand the disk operations happening in a running MongoDB instance.
  • mongooplog --- Shows what's happening in the MongoDB oplog.
  • Bsondump --- Converts BSON files into human-readable formats including JSON.

1.4 Why MongoDB?

1.4.1 MongoDB versus other databases

Table 1.1 Database families
ExamplesData modelScalability modelUse cases
Simple key-value storesMemcachedkey-value,where the value is a binary blob.Variable.Memcached can scale across nodes, converting all available RAM into a single,monolithic datastore.Caching.Web ops.
Sophisticated value storesHBase,Cassandra,Riak KV,Redis ,CouchDBVariable.Cassandra uses a key-value structure known as a column.HBase and Redis store binary blobs.CouchDB stores JSON documents.Eventually consistent,multinode distribution for high availability and easy failoverHigh-throughput verticals(activityfeeds,message queues).Caching. Web ops.
Relational DatabasesOracle Database, IBM DB2,Microsoft SQL Server,MySQL, PostgreSQLTablesVertical scaling.Limited support for clustering and manual partitioning.System requiring transactions (banking,finance) or SQL.Normalized data model.

1.5 Summary

To summarize,MongoDB is an open source. document-based database management system.Designed for the data and scalability requirements of modern internet applications.MongDB  features  dynamic queries and secondary indexes,fast atomic updates and complex aggregations, and support for replication with automatic failover and sharding for scaling horizontally.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值