E-Book, Englisch, 328 Seiten
Membrey / Plugge / Hawkins The Definitive Guide to MongoDB
1. ed
ISBN: 978-1-4302-3052-6
Verlag: Apress
Format: PDF
Kopierschutz: 1 - PDF Watermark
The NoSQL Database for Cloud and Desktop Computing
E-Book, Englisch, 328 Seiten
ISBN: 978-1-4302-3052-6
Verlag: Apress
Format: PDF
Kopierschutz: 1 - PDF Watermark
MongoDB, a cross-platform NoSQL database, is the fastest-growing new database in the world. MongoDB provides a rich document-oriented structure with dynamic queries that you'll recognize from RDBMS offerings such as MySQL. In other words, this is a book about a NoSQL database that does not require the SQL crowd to re-learn how the database world works! MongoDB has reached 1.0 and boasts 50,000+ users. The community is strong and vibrant and MongoDB is improving at a fast rate. With scalable and fast databases becoming critical for today's applications, this book shows you how to install, administer and program MongoDB without pretending SQL never existed.
Hailing from the U.K., Peter Membrey has worked for Red Hat, holds a RHCE certification, and worked and taught at a number of educational institutions since the beginning of his career. He knows what Linux users like and need, and hopes that CentOS will get the kudos it deserves. He lives in Hong Kong and is teaching and consulting on all matters to do with Linux Enterprise networking, while studying for his master's degree.
Autoren/Hrsg.
Weitere Infos & Material
1;Title Page;1
2;Copyright Page;2
3;Contents at a Glance;4
4;Table of Contents;5
5;About the Authors;16
6;About the Technical Reviewer;17
7;Acknowledgments;18
8;Introduction;20
9;PART I Basics;21
10;Chapter 1 Introduction to MongoDB;22
10.1;Reviewing the MongoDB Philosophy;22
10.1.1;Using the Right Tool for the Right Job;22
10.1.2;Lacking Innate Support for Transactions;24
10.1.3;Drilling Down on JSON and How It Relates to MongoDB;24
10.1.4;Adopting a Non-Relational Approach;26
10.1.5;Opting for Performance vs. Features;27
10.1.6;Running the Database Anywhere;28
10.2;Fitting Everything Together;28
10.2.1;Generating or Creating a Key;28
10.2.2;Using Keys and Values;29
10.2.3;Implementing Collections;30
10.2.4;Understanding Databases;30
10.3;Reviewing the Feature List;30
10.3.1;Using Document-Orientated Storage (BSON);30
10.3.2;Supporting Dynamic Queries;31
10.3.3;Indexing Your Documents;32
10.3.4;Leveraging Geospatial Indexes;32
10.3.5;Profiling Queries;33
10.3.6;Updating Information In-Place;33
10.3.7;Storing Binary Data;33
10.3.8;Replicating Data;34
10.3.9;Implementing Auto Sharding;34
10.3.10;Using Map and Reduce Functions;35
10.4;Getting Help;35
10.4.1;Visiting the Website;35
10.4.2;Chatting with the MongoDB Developers;35
10.4.3;Cutting and Pasting MongoDB Code;36
10.4.4;Finding Solutions on Google Groups;36
10.4.5;Leveraging the JIRA Tracking System;36
10.5;Summary;36
11;Chapter 2 Installing MongoDB;37
11.1;Choosing Your Version;37
11.1.1;Understanding the Version Numbers;38
11.2;Installing MongoDB on Your System;38
11.2.1;Installing MongoDB Under Linux;38
11.2.1.1;Installing MongoDB Through the Repositories;39
11.2.1.2;Installing MongoDB Manually;39
11.2.2;Installing MongoDB Under Windows;40
11.3;Running MongoDB;40
11.3.1;Prerequisites;40
11.3.2;Surveying the Installation Layout;41
11.3.3;Using the MongoDB Shell;41
11.4;Installing Additional Drivers;42
11.4.1;Installing the PHP driver;43
11.4.1.1;Getting MongoDB for PHP;43
11.4.1.2;Installing PHP on Unix-based Platforms Automatically;44
11.4.1.3;Installing PHP on Unix-Based Platforms Manually;45
11.4.1.4;Installing PHP on Windows;46
11.4.2;Confirming Your PHP Installation Works;46
11.4.2.1;Connecting to and Disconnecting from the PHP Driver;47
11.4.3;Installing the Python Driver;48
11.4.3.1;Installing PyMongo under Linux;48
11.4.3.2;Installing PyMongo Automatically;48
11.4.3.3;Installing PyMongo Manually;49
11.4.3.4;Installing PyMongo Under Windows;49
11.4.4;Confirming Your PyMongo Installation Works;51
11.5;Summary;51
12;Chapter 3 The Data Model;52
12.1;Designing the Database;52
12.1.1;Drilling Down on Collections;53
12.1.2;Using Documents;55
12.1.2.1;Embedding vs. Referencing Information in Documents;56
12.1.3;Creating the _id Field;57
12.2;Building Indexes;58
12.2.1;Impacting Performance with Indexes;59
12.3;Implementing Geospatial Indexing;59
12.3.1;Querying Geospatial Information;60
12.4;Using MongoDB in the Real World;63
12.5;Summary;63
13;Chapter 4 Working with Data;64
13.1;Navigating Your Databases;64
13.1.1;Viewing Available Databases and Collections;64
13.2;Inserting Data into Collections;65
13.3;Querying for Data;66
13.3.1;Using the Dot Notation;68
13.3.2;Using the Sort, Limit, and Skip Functions;69
13.3.3;Working with Capped Collections, Natural Order, and $natural;70
13.3.4;Retrieving a Single Document;72
13.3.5;Using the Aggregation Commands;72
13.3.5.1;Returning the Number of Documents with Count();72
13.3.5.2;Retrieving Unique Values with Distinct();72
13.3.5.3;Grouping Your Results;73
13.3.6;Working with Conditional Operators;74
13.3.6.1;Performing Greater and Less Than Comparisons;75
13.3.6.2;Retrieving All Documents but Those Specified;76
13.3.6.3;Specifying an Array of Matches;76
13.3.6.4;Finding a Value Not in an Array;76
13.3.6.5;Matching all Attributes in a Document;76
13.3.6.6;Searching for Multiple Expressions in a Document;77
13.3.6.7;Retrieving a Document with $slice;77
13.3.6.8;Searching for Odd/Even Integers;78
13.3.6.9;Filtering Results with $size;78
13.3.6.10;Returning a Specific Field Object;79
13.3.6.11;Matching Results Based on the BSON Type;79
13.3.6.12;Matching an Entire Array;80
13.3.6.13;$not (meta-operator);81
13.3.6.14;Specifying Additional Query Expressions;82
13.3.7;Leveraging Regular Expressions;82
13.4;Updating Data;82
13.4.1;Updating with update();82
13.4.2;Implementing an Upsert with the save() Command;83
13.4.3;Updating Information Automatically;83
13.4.3.1;Incrementing a Value with $inc;83
13.4.3.2;Setting a Field’s Value;84
13.4.3.3;Deleting a Given Field;84
13.4.3.4;Appending a Value to a Specified Field;85
13.4.3.5;Specifying Multiple Values in an Array;85
13.4.3.6;Adding Data to an Array with $addToSet;85
13.4.3.7;Removing Elements from an Array;86
13.4.3.8;Removing Each Occurrence of a Specified Value;87
13.4.3.9;Removing Multiple Elements from an Array;87
13.4.4;Specifying the Position of a Matched Array;87
13.4.5;Atomic Operations;88
13.4.5.1;Using the Update if Current Method;89
13.4.6;Modifying and Returning a Document Atomically;90
13.5;Renaming a Collection;91
13.6;Removing Data;91
13.7;Referencing a Database;92
13.7.1;Referencing Data Manually;92
13.7.2;Referencing Data with DBRef;93
13.8;Implementing Index-Related Functions;95
13.8.1;Surveying Index-Related Commands;97
13.8.2;Forcing a Specified Index to Query Data;97
13.8.3;Constraining Query Matches;97
13.9;Summary;98
14;Chapter 5: GridFS;99
14.1;Filling in Some Background;99
14.2;Working with GridFS;100
14.3;Getting Started with the Command-Line Tools;101
14.3.1;Using the _id Key;102
14.3.2;Working with Filenames;102
14.3.3;Determining a File’s Length;102
14.3.4;Working with Chunk Sizes;103
14.3.5;Tracking the Upload Date;103
14.3.6;Hashing Your Files;103
14.4;Looking Under MongoDB’s Hood;104
14.4.1;Using the Search Command;106
14.4.2;Deleting;106
14.4.3;Retrieving Files from MongoDB;107
14.4.4;Summing up mongofiles;107
14.5;Exploiting the Power of Python;107
14.5.1;Connecting to the Database;108
14.5.2;Accessing the Words;109
14.6;Putting Files into MongoDB;109
14.7;Retrieving Files from GridFS;110
14.8;Deleting Files;110
14.9;Summary;111
15;PART II Developing;112
16;Chapter 6 PHP and MongoDB;113
16.1;Comparing Documents in MongoDB and PHP;113
16.2;MongoDB Classes;114
16.3;Connecting and Disconnecting;115
16.4;Inserting Data;116
16.5;Listing Your Data;118
16.5.1;Returning a Single Document;118
16.5.2;Listing All Documents;119
16.5.3;Using Query Operators;120
16.5.4;Querying for Specific Information;120
16.5.5;Sorting, Limiting, and Skipping Items;121
16.5.6;Counting the Number of Matching Results;122
16.5.7;Grouping Data with Map/Reduce;123
16.5.8;Specifying the Index with Hint;125
16.5.9;Refining Queries with Conditional Operators;125
16.5.9.1;Using the $lt, $gt, $lte, and $gte Operators;126
16.5.9.2;Finding Documents that Don’t Match a Value;128
16.5.9.3;Matching Any of Multiple Values with $in;128
16.5.9.4;Matching All Criteria in a Query with $all;129
16.5.9.5;Searching for Multiple Expressions with $or;129
16.5.9.6;Retrieving a Specified Number of Items with $slice;130
16.5.9.7;Determining Whether a Field Has a Value;131
16.5.10;Regular Expressions;132
16.6;Modifying Data with PHP;133
16.6.1;Updating via update();133
16.6.2;Saving Time with Modifier Operators;135
16.6.2.1;Increasing the Value of a Specific Key with $inc;135
16.6.2.2;Changing the Value of a Key with $set;136
16.6.2.3;Deleting a Field with $unset;136
16.6.2.4;Appending a Value to a Specified Field with $push;137
16.6.2.5;Adding Multiple Values to a Key with $pushAll;137
16.6.2.6;Adding Data to an Array with $addToSet;137
16.6.2.7;Removing an Element from an Array with $pop;138
16.6.2.8;Removing Each Occurrence of a Value with $pull;139
16.6.2.9;Removing Each Occurrence of Multiple Elements;139
16.6.3;Upserting Data with save();139
16.6.4;Modifying a Document Atomically;140
16.7;Deleting Data;143
16.8;DBRef;144
16.8.1;Retrieving the Information;146
16.9;GridFS and the PHP Driver;146
16.9.1;Storing Files;147
16.9.2;Adding More Metadata to Stored Files;147
16.9.3;Retrieving Files;148
16.9.4;Deleting Data;149
16.10;Summary;149
17;Chapter 7 Python and MongoDB;150
17.1;Working with Documents in Python;150
17.2;Using PyMongo Modules;151
17.3;Connecting and Disconnecting;151
17.4;Inserting Data;152
17.5;Finding Your Data;153
17.5.1;Finding a Single Document;153
17.5.2;Finding Multiple Documents;154
17.5.3;Using Dot Notation;155
17.5.4;Returning Fields;155
17.5.5;Simplifying Queries with Sort, Limit, and Skip;156
17.5.6;Aggregating Queries;158
17.5.6.1;Counting Items with Count();158
17.5.6.2;Counting Unique Items with Distinct();158
17.5.6.3;Grouping Data with map_reduce();159
17.5.7;Specifying an Index with Hint();160
17.5.8;Refining Queries with Conditional Operators;161
17.5.8.1;Using the $lt, $gt, $lte, and $gte Operators;161
17.5.8.2;Searching for Non-Matching Values with $ne;163
17.5.8.3;Specifying an Array of Matches with $in;163
17.5.8.4;Specifying Against an Array of Matches with $nin;164
17.5.8.5;Finding Documents that Match an Array’s Values;164
17.5.8.6;Specifying Multiple Expressions to Match with $or;164
17.5.8.7;Retrieving Items from an Array with $slice;165
17.5.9;Conducting Searches with Regular Expression;166
17.6;Modifying the Data;167
17.6.1;Updating Your Data;167
17.6.2;Modifier Operators;169
17.6.2.1;Increasing an Integer Value with $inc;169
17.6.2.2;Changing an Existing Value with $set;169
17.6.2.3;Removing a Key/Value Field with $unset;170
17.6.2.4;Adding a Value to an Array with $push;170
17.6.2.5;Adding Multiple Values to an Array with $pushAll;171
17.6.2.6;Adding a Value to an Existing Array with $addToSet;171
17.6.2.7;Removing an Element from an Array with $pop;172
17.6.2.8;Removing a Specific Value with $pull;172
17.6.3;Saving Documents Quickly with Save();173
17.6.4;Modifying a Document Atomically;174
17.6.5;Putting the Parameters to Work;174
17.7;Deleting Data;175
17.8;Creating a Link Between Two Documents;176
17.8.1;Retrieving the Information;178
17.9;Summary;179
18;Chapter 8 Creating a Blog Application with the PHP Driver;180
18.1;Designing the Application;181
18.2;Listing the Posts;182
18.2.1;Paging with PHP and MongoDB;184
18.3;Looking at a Single Post;185
18.3.1;Specifying Additional Variables;186
18.3.2;Viewing and Adding Comments;187
18.4;Searching the Posts;188
18.5;Adding, Deleting, and Modifying Posts;189
18.5.1;Adding a New Post;190
18.5.2;Editing a Post;191
18.5.3;Deleting a Post;192
18.6;Creating the Index Pages;193
18.7;Recapping the blog Application;194
18.8;Summary;203
19;PART III Advanced;204
20;Chapter 9 Database Administration;205
20.1;Using Administrative Tools;206
20.1.1;mongo, the MongoDB Console;206
20.1.2;Using Third-Party Administration Tools;206
20.2;Backing up the MongoDB Server;206
20.2.1;Creating a Backup 101;206
20.2.2;Backing up a Single Database;209
20.2.3;Backing up a Single Collection;209
20.3;Digging Deeper into Backups;209
20.4;Restoring Individual Databases or Collections;210
20.4.1;Restoring a Single Database;211
20.4.2;Restoring a Single Collection;211
20.5;Automating Backups;211
20.5.1;Using a Local Datastore;211
20.5.2;Using a Remote (Cloud-Based) Datastore;214
20.6;Backing up Large Databases;215
20.6.1;Using a Slave Server for Backups;215
20.6.2;Creating Snapshots with a Journaling Filesystem;215
20.6.3;Disk Layout to Use with Volume Managers;217
20.7;Importing Data into MongoDB;218
20.8;Exporting Data from MongoDB;219
20.9;Securing Your Data;220
20.9.1;Restricting Access to a MongoDB Server;220
20.10;Protecting Your Server with Authentication;220
20.10.1;Adding an Admin User;221
20.10.2;Enabling Authentication;221
20.10.3;Authenticating in the mongo Console;221
20.10.4;Changing a User’s Credentials;222
20.10.5;Adding a Read-Only User;223
20.10.6;Deleting a User;223
20.10.7;Using Authenticated Connections in a PHP Application;224
20.11;Managing Servers;224
20.11.1;Starting a Server;224
20.11.2;Reconfiguring a Server;225
20.11.3;Getting the Server’s Version;226
20.11.4;Getting the Server’s Status;226
20.11.5;Shutting Down a Server;228
20.12;Using MongoDB Logfiles;229
20.13;Validating and Repairing Your Data;229
20.13.1;Repairing a Server;229
20.13.2;Validating a Single Collection;230
20.13.3;Repairing Collection Validation Faults;231
20.13.3.1;Repairing a Collection’s Indexes;232
20.13.4;Repairing a Collection’s Datafiles;232
20.14;Upgrading MongoDB;233
20.15;Monitoring MongoDB;233
20.15.1;Rolling Your Own Stat Monitoring Tool;234
20.16;Using the mongod Web Interface;235
20.17;Summary;235
21;Chapter 10 Optimization;237
21.1;Optimizing Your Server Hardware for Performance;237
21.1.1;Understanding How MongoDB Uses Memory;237
21.1.2;Choosing the Right Database Server Hardware;238
21.2;Evaluating Query Performance;238
21.3;MongoDB Profiler;238
21.3.1;Enabling and Disabling the DB Profiler;239
21.3.1.1;Finding Slow Queries;239
21.3.2;Analyzing a Specific Query with explain();240
21.3.3;Using Profile and explain() to Optimize a Query;241
21.4;Managing Indexes;244
21.4.1;Listing Indexes;245
21.4.2;Creating a Simple Index;245
21.4.3;Creating a Compound Index;246
21.4.3.1;Creating Subdocument Compound Indexes;246
21.4.3.2;Constructing a Compound Index Manually;246
21.5;Specifying Index Options;247
21.5.1;Creating an Index in the Background with {background:true};247
21.5.1.1;Killing the Indexing Process;247
21.5.2;Creating an Index with a Unique Key {unique:true};248
21.5.3;Dropping Duplicates Automatically with {dropdups:true};248
21.5.4;Dropping an Index;248
21.5.5;Re-Indexing a Collection;249
21.6;How MongoDB Selects Which Indexes It Will Use;249
21.7;Using Hint() to Force Using a Specific Index;250
21.8;Optimizing the Storage of Small Objects;250
21.9;Summary;251
22;Chapter 11 Replication;252
22.1;Spelling Out MongoDB’s Replication Goals;253
22.1.1;Improving Scalability;253
22.1.2;Improving Durability/Reliability;253
22.1.3;Providing Isolation;254
22.2;Drilling Down on the Oplog;254
22.3;Implementing Single Master/Single Slave Replication;255
22.3.1;Setting Up a Master/Slave Replication Configuration;256
22.3.1.1;Examining the Slave;257
22.4;Implementing Single Master/Multiple Slave Replication;259
22.5;Configuring a Master/Slave Replication System;259
22.6;Resynchronizing a Master/Slave Replication System;260
22.6.1;Issuing a Manual Resync Command to the Slave;261
22.6.2;Resyncing by Deleting the Slaves Datafiles;261
22.6.3;Resyncing a Slave with the --fastsync Option;261
22.7;Implementing Multiple Master/Single Slave Replication;262
22.7.1;Setting up a Multiple Master/Slave Replication Configuration;262
22.8;Exploring Various Replication Scenarios;265
22.8.1;Implementing Cascade Replication;265
22.8.2;Implementing Master/Master Replication;265
22.8.3;Implementing Interleaved Replication;266
22.9;Using Replica Pairs;267
22.9.1;Resolving Server Disputes with an Arbiter;272
22.10;Implementing Advanced Clustering with Replica Sets;273
22.10.1;Creating a Replica Set;275
22.10.2;Getting a Replica Set Member Up and Running;276
22.10.3;Adding a Server to a Replica Set;277
22.10.4;Managing Replica Sets;278
22.10.4.1;Inspecting an Instance’s Status with rs.status();279
22.10.4.2;Forcing a New Election with rs.stepDown();280
22.10.4.3;Determining If a Member is the Primary Server;281
22.10.5;Configuring the Options for Replica Set Members;282
22.10.5.1;Organization of the Members Structure;282
22.10.5.2;Exploring the Options Available in the Settings Structure;283
22.10.6;Determining the Status of Replica Sets;284
22.10.7;Connecting to a Replica Set from Your Application;284
22.10.7.1;Viewing Replica Set Status with the Web Interface;285
22.11;Summary;286
23;Chapter 12 Sharding;287
23.1;Exploring the Need for Sharding;287
23.2;Partitioning Horizontal and Vertical Data;288
23.2.1;Partitioning Data Vertically;288
23.2.2;Partitioning Data Horizontally;288
23.3;Analyzing a Simple Sharding Scenario;289
23.4;Implementing Sharding with MongoDB;290
23.5;Setting Up a Sharding Configuration;292
23.5.1;Adding a New Shard to the Cluster;295
23.6;Removing a Shard from the Cluster;297
23.7;Determining How You’re Connected;298
23.8;Listing the Status of a Sharded Cluster;298
23.9;Using Replica Sets to Implement Shards;300
23.10;Sharding to Improve Performance;300
23.11;Summary;301
24;Index;302




