Thông tin tài liệu
MANNING
Kyle Banker
IN ACTION
MongoDB in Action
Download from Wow! eBook <www.wowebook.com>
Download from Wow! eBook <www.wowebook.com>
MongoDB in Action
KYLE BANKER
MANNING
SHELTER ISLAND
Download from Wow! eBook <www.wowebook.com>
For online information and ordering of this and other Manning books, please visit
www.manning.com. The publisher offers discounts on this book when ordered in quantity.
For more information, please contact
Special Sales Department
Manning Publications Co.
20 Baldwin Road
PO Box 261
Shelter Island, NY 11964
Email: orders@manning.com
©2012 by Manning Publications Co. All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in
any form or by means electronic, mechanical, photocopying, or otherwise, without prior written
permission of the publisher.
Many of the designations used by manufacturers and sellers to distinguish their products are
claimed as trademarks. Where those designations appear in the book, and Manning
Publications was aware of a trademark claim, the designations have been printed in initial caps
or all caps.
Recognizing the importance of preserving what has been written, it is Manning’s policy to have
the books we publish printed on acid-free paper, and we exert our best efforts to that end.
Recognizing also our responsibility to conserve the resources of our planet, Manning books
are printed on paper that is at least 15 percent recycled and processed without the use of
elemental chlorine.
Manning Publications Co. Development editors: Jeff Bleiel, Sara Onstine
20 Baldwin Road Copyeditor: Benjamin Berg
PO Box 261 Proofreader: Katie Tennant
Shelter Island, NY 11964 Typesetter: Dottie Marsico
Cover designer: Marija Tudor
ISBN 9781935182870
Printed in the United States of America
1 2 3 4 5 6 7 8 9 10 – MAL – 16 15 14 13 12 11
Download from Wow! eBook <www.wowebook.com>
This book is dedicated to peace and human dignity
and to all those who work for these ideals
Download from Wow! eBook <www.wowebook.com>
Download from Wow! eBook <www.wowebook.com>
vii
brief contents
PART 1 GETTING STARTED 1
1
■
A database for the modern web 3
2
■
MongoDB through the JavaScript shell 23
3
■
Writing programs using MongoDB 37
PART 2 APPLICATION DEVELOPMENT IN MONGODB 53
4
■
Document-oriented data 55
5
■
Queries and aggregation 76
6
■
Updates, atomic operations, and deletes 101
PART 3 MONGODB MASTERY 127
7
■
Indexing and query optimization 129
8
■
Replication 156
9
■
Sharding 184
10
■
Deployment and administration 218
Download from Wow! eBook <www.wowebook.com>
Download from Wow! eBook <www.wowebook.com>
ix
contents
preface xv
acknowledgments xvii
about this book xviii
about the cover illustration xxi
PART 1 GETTING STARTED 1
1
A database for the modern web 3
1.1 Born in the cloud 5
1.2 MongoDB’s key features 5
The document data model 5
■
Ad hoc queries 8
■
Secondary
indexes 10
■
Replication 10
■
Speed and durability 11
Scaling 12
1.3 MongoDB’s core server and tools 13
The core server 14
■
The JavaScript shell 14
■
Database
drivers 15
■
Command-line tools 16
1.4 Why MongoDB? 16
MongoDB versus other databases 17
■
Use cases and
production deployments 19
1.5 Tips and limitations 21
1.6 Summary 22
Download from Wow! eBook <www.wowebook.com>
[...]... CONTENTS 2 MongoDB through the JavaScript shell 2.1 23 Diving into the MongoDB shell 24 Starting the shell 24 Inserts and queries documents 26 Deleting data 28 25 ■ ■ Updating ■ 2.2 Creating and querying with indexes 29 Creating a large collection 2.3 Basic administration 29 ■ Indexing and explain() 33 Getting database information 33 2.4 2.5 3 31 How commands work ■ 34 Getting help 35 Summary 36 Writing programs... ones you’d find in an RDMBS; ascending, descending, unique, compound-key, and even geospatial indexes are supported Because MongoDB and most 1 A working replica set RDBMSs use the same data structure for their indexes, advice for managing indexes in both of these systems is Secondary Secondary compatible We’ll begin looking at indexes in the next chapter, and because an understanding of indexing is so... entity_type_id smallint(5) attribute_id smallint(5) store_id smallint(5) entity_id int(10) value datetime catalog_product_entity_decimal value_id int(11) entity_type_id smallint(5) attribute_id smallint(5) store_id smallint(5) entity_id int(10) value decimal(12, 4) catalog_product_entity_int value_id int(11) entity_type_id smallint(5) attribute_id smallint(5) store_id smallint(5) entity_id int(10) value int(11)... http:/ /mongodb- book.com as well as from the publisher’s website at http:// manning.com/MongoDBinAction Software requirements To get the most out of this book, you’ll need to have MongoDB installed on your system Instructions for installing MongoDB can be found in appendix A and also on the official MongoDB website (http:/ /mongodb. org) If you want to run the Ruby driver examples, you’ll also need to install... Ruby Again, consult appendix A for instructions on this Author Online The purchase of MongoDB in Action includes free access to a private forum run by Manning Publications where you can make comments about the book, ask technical questions, and receive help from the author and other users To access and subscribe to the forum, point your browser to www.manning.com/MongoDBinAction This page provides information... spatial indexing to query on geo-coordinates Code conventions and downloads All source code in the listings and in the text is presented in a fixed-width font, which separates it from ordinary text Code annotations accompany some of the listings, highlighting important concepts In some cases, numbered bullets link to explanations that follow in the text As an open source project, 10gen keeps MongoDB s... Secondary indexes in MongoDB are implemented as B-trees B-tree indexes, also the default for most relational databases, are optimized for a variety of queries, including range scans and queries with sort clauses By 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... of indexing and query optimization Chapter 8 concentrates on replication, with strategies for deploying MongoDB for high availability and read scaling Chapter 9 describes sharding, MongoDB s path to horizontal scalability And chapter 10 provides a series of best practices for deploying, administering, and troubleshooting MongoDB installations The book ends with five appendixes Appendix A covers installation... 36 Writing programs using MongoDB 37 3.1 MongoDB through the Ruby lens 38 Installing and connecting 38 Inserting documents in Ruby 39 Queries and cursors 40 Updates and deletes 41 Database commands 42 ■ ■ 3.2 How the drivers work 43 Object ID generation 43 3.3 ■ BSON Building a simple application Setting up 3.4 ■ Summary 47 ■ 44 ■ Over the network 45 47 Gathering data 48 ■ Viewing the archive 50 52... 249 Binary data and GridFS 260 MongoDB in PHP, Java, and C++ Spatial indexing 274 index 279 266 Download from Wow! eBook Download from Wow! eBook preface Databases are the workhorses of the information age Like Atlas, they go largely unnoticed in supporting the digital world we’ve come to inhabit It’s easy to forget that our digital interactions, from commenting . 126 PART 3 MONGODB MASTERY 127 7 Indexing and query optimization 129 7.1 Indexing theory 130 A thought experiment 130 ■ Core indexing concepts 133 B-trees 136 7.2 Indexing in practice 137 Index types. MongoDB through the JavaScript shell 23 2.1 Diving into the MongoDB shell 24 Starting the shell 24 ■ Inserts and queries 25 ■ Updating documents 26 ■ Deleting data 28 2.2 Creating and querying. Getting help 35 2.5 Summary 36 3 Writing programs using MongoDB 37 3.1 MongoDB through the Ruby lens 38 Installing and connecting 38 ■ Inserting documents in Ruby 39 Queries and cursors 40 ■ Updates
Ngày đăng: 29/03/2014, 20:20
Xem thêm: MongoDB in Action pdf, MongoDB in Action pdf, 3 MongoDB’s core server and tools, 3 Nuts and bolts: on databases, collections, and documents, 4 Nuts and bolts: MongoDB updates and deletes