20,39 €
MongoDB is a high-performance and feature-rich Document Orientated Database. This popular, highly scalableNoSQL database is used to power some of the world's most used applications and websites.
MongoDB Starter is designed to get you working with MongoDB as quickly as possible. Starting with the installation and setup, we quickly show you how to start importing your data into the database. Furthermore, you will learn about CRUD operations in MongoDB, its Map Reduce support, schema design, and performance tuning operations.
After successfully installing and setting up MongoDB, you will be introduced to important configuration parameters and the terminologies used in the Mongo world and their equivalent in the relational world. You will learn how to import data into the database and connect to the MongoDB from the Mongo shell and execute some queries. We will then move on to advanced topics such as performing insert, update and upsert(update + insert) operations, executing advanced queries, schema design concepts, and creating indexes for performance. MongoDB Starter finishes with a look at the new aggregation framework, Map Reduce operations, and how to bulk import and export data.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 111
Veröffentlichungsjahr: 2013
Copyright © 2013 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: July 2013
Production Reference: 1220713
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78216-970-3
www.packtpub.com
Author
Amol Nayak
Reviewer
Varad Meru
Acquisition Editor
Joanna Fitzpatrick
Commissioning Editor
Sruthi Kutty
Technical Editors
Dylan Fernandes
Pragati Singh
Project Coordinator
Suraj Bist
Proofreader
Aaron Nash
Graphics
Abhinash Sahu
Production Coordinator
Prachali Bhiwandkar
Cover Work
Prachali Bhiwandkar
Cover Image
Nitesh Thakur
Amol Nayak has been working in the Java/JEE space for the past seven years and is currently employed at a leading investment bank where he is working on cutting edge technologies, predominantly open source. He is playing around with MongoDB by developing prototypes for various use cases at his workplace. He is an open source enthusiast and supports it by contributing to the open source frameworks and promoting them. He has significant ongoing contribution to the Spring Integration project, where he has worked on various adapters for JPA, XQuery, MongoDB, push notification to mobile devices, and Amazon Web Services (AWS). He has also made contributions to the Spring Data Mongo project.
I would like to thank everyone at Packt who has been involved with this book. It all started when Ashish from Packt approached me to author a starter book in Mongo. I would like to thank him for giving me this opportunity. It has an excellent experience full of learning along the way. Being my first title, I struggled initially with the process of writing and submitting the content. If it hadn't been for Suraj, Sruthi, and Yogesh from Packt, I wouldn't have been able to deliver the content on time. Suraj and Sruthi showed great patience and helped me a great deal in formatting and organizing the content that I submitted.
A special thanks to Varad Meru, the technical reviewer of the book who agreed to review the contents at very short notice. If it hadn't been for him, who reviewed the content till late at night, we wouldn't have been in a position to go ahead with the publishing of the title on time. I would like to thank the technical editor, Pragati for her exceptionally quick turnaround time which helped get the book ahead into production in no time.
Finally I would like to thank the other staff from Packt who were involved in the book's publishing process but haven't interacted with me, my office colleagues who supported me a great deal, friends, and my mom, who I wasn't able to devote much time to owing to the schedules for the delivery of the content of the book.
Varad Meru has experience in the fields of machine learning, information retrieval systems, and search engines and has worked on various projects/products ranging from core machine learning projects such as e-commerce recommender systems, e-mail analytics, and data science platforms to Cloud Infrastructure Products. He is interested in building Intelligent Systems using machine learning, data mining, data visualization, and distributed and parallel Algorithms.
He is currently working as a Software Development Engineer at Orzota, Inc. Previously he worked at Persistent Systems Ltd., Pune as a part of the Big Data team there. He graduated from Shivaji University in 2011.
You might want to visit www.packtpub.com for support files and downloads related to your book.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.packtpub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.
At www.packtpub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can access, read and search across Packt's entire library of books.
If you have an account with Packt at www.packtpub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access.
Welcome to Instant MongoDB. This book has been developed to provide you with all the information that you need to get started with MongoDB. You will learn the basics of MongoDB, get started by installing it, and then perform various operations on it such as inserting, updating, and querying data and discover some tips and tricks for using MongoDB.
This document contains the following sections:
So what is MongoDB? explains what MongoDB actually is, what you can do with it, and why it's so great.
Installation shows you how to download and install MongoDB with minimum effort, introducing the important configuration parameters and then how to set it up so that you can use it as soon as possible.
Quick start – setting up database and querying starts off by giving a brief comparison of terminologies from the Mongo world and their equivalent in the relational world. We then import some data in the database; this is the data we would be playing around with for most of the book. We conclude this section by connecting to the MongoDB from the Mongo shell and executing some queries to get a feel of how the queries and the data look. We basically would only be scratching the surface of this technology in this section.
Top 4 features you need to know about helps us learn how to perform various operations on MongoDB from the Mongo shell. By the end of this section you will be able to connect to a database from the shell, perform insert, update, and upsert (update + insert) operations, execute advanced queries, schema design concepts, and creating indexes for performance. Also, you will finally learn about the new aggregation framework and Map reduce operations.
People and places you should get to know lists many useful links to the project page and forums. Also, since every Open Source project is centered on a community, it provides a number of helpful articles, tutorials, and blogs which will enrich your learning process.
Put simply, MongoDB is a Documented Oriented Database.
While it may vary for various implementations of different Document Oriented Databases available, as far as MongoDB is concerned it is a BSON document, which stands for Binary JSON. JSON (JavaScript Object Notation) is an open standard developed for human readable data exchange. Though a thorough knowledge of JSON is not really important to understand MongoDB, for keen readers the URL to its RFC is http://tools.ietf.org/html/rfc4627. Also, the BSON specification can be found at http://bsonspec.org/. Since MongoDB stores the data as BSON documents, it is a Document Oriented Database.
Consider the following example where we represent a person using JSON:
As we can see, a JSON document always starts and ends with curly braces and has all the content within these braces. Multiple fields and values are separated by commas, with a field name always being a string value and the value being of any type ranging from string, numbers, date, array, another JSON document, and so on. For example in "firstName":"Jack", the firstName is the name of the field whereas Jack is the value of the field.
Many of you would probably be wondering why we need another database when we already have good old relational databases. We will try to see a few drivers from its introduction back in 2009.
Relational databases are extremely rich in features. But these features don't come for free; there is a price to pay and it is done by compromising on the scalability and flexibility. Let us see these one by one.
It is a factor used to measure the ease with which a system can accommodate the growing amount of work or data. There are two ways in which you can scale your system: scale up, also known as scale vertically or scale out, also known as scale horizontally. Vertical scalability can simply be put up as an approach where we say "Need more processing capabilities? Upgrade to a bigger machine with more cores and memory". Unfortunately, with this approach we hit a wall as it is expensive and technically we cannot upgrade the hardware beyond a certain level. You are then left with an option to optimize your application, which might not be a very feasible approach for some systems which are running in production for years.
On the other hand, Horizontal scalability can be described as an approach where we say "Need more processing capabilities? Simple, just add more servers and multiply the processing capabilities". Theoretically this approach gives us unlimited processing power but we have more challenges in practice. For many machines to work together, there would be a communication overhead between them and the probability of any one of these machines being down at a given point of time is much higher.
MongoDB enables us to scale horizontally easily, and at the same time addresses the problems related to scaling horizontally to a great extent. The end result is that it is very easy to scale MongoDB with increasing data as compared to relational databases.
MongoDB doesn't have the concept of creation of schema as we have in relational databases. The document that we just saw can have an arbitrary structure when we store them in the database. This feature makes it very easy for us to model and store relatively unstructured/complex data, which becomes difficult to model in a relational database. For example, product catalogues of an e-commerce application containing various items and each having different attributes. Also, it is more natural to use JSON in application development than tables from relational world.
Ok, it looks good, but what is the catch? Where not to use MongoDB?
To achieve the goal of letting MongoDB scale out easily, it had to do away with features like joins and multi document/distributed transactions. Now, you must be wondering it is pretty useless as we have taken away two of the most important features of the relational database. However, to mitigate the problems of joins is one of the reasons why MongoDB is document oriented. If you look at the preceding JSON document for the person, we have the address and the phone number as a part of the document. In relational database, these would have been in separate tables and retrieved by joining these tables together.
