Computer Science

What is MongoDB

MongoDB is a popular NoSQL database that stores data in flexible, JSON-like documents. It is designed to scale horizontally across multiple servers and can handle large amounts of unstructured data. MongoDB is commonly used in web applications and other modern software development projects.

Written by Perlego with AI-assistance

10 Key excerpts on "What is MongoDB"

  • Seven NoSQL Databases in a Week
    • Xun (Brian) Wu, Sudarshan Kadambi, Devram Kandhare, Aaron Ploetz(Authors)
    • 2018(Publication Date)
    • Packt Publishing
      (Publisher)

    MongoDB

    MongoDB is an open source, document-oriented, and cross-platform database. It is primarily written in C++. It is also the leading NoSQL database and tied with the SQL database in fifth position after PostgreSQL. It provides high performance, high availability, and easy scalability. MongoDB uses JSON-like documents with schema. MongoDB, developed by MongoDB Inc., is free to use. It is published under a combination of the GNU Affero General Public License and the Apache License.
    Let's go through the MongoDB features:
    • Rich query support : We can query the database as we do with SQL databases. It has a large query set that supports insert, update, delete and select operations. MongoDB supports fields, range queries, and regular expressions. Queries also support the projection where they return a value for specific keys.
    • Indexing : MongoDB supports primary and secondary indices in its fields.
    • Replication : Replication means providing more than one copy of data. MongoDB provides multiple copies of data with multiple servers. It provides fault tolerance, if one database server goes down, the application uses other database servers.
    • Load balancing : Replica sets provide multiple copies of data. MongoDB can scale read operation by client request directly to the secondary node. This divides loads across multiple servers.
    • File storage : We can store documents up to 6 MB directly to the MongoDB JSON field. For documents exceeding the size limit of 16 MB, MongoDB provides GridFS to store in chunks.
    • Aggregation : The aggregate function takes a number of records and calculates single results like sum, min, and max. MongoDB provides a data pipeline and multistage pipeline to move large data to the aggregate function which improves performance.
    Passage contains an image

    Installing of MongoDB

    You can download the latest version of MongoDB here: https://www.mongodb.com/download-center#community
  • MongoDB Fundamentals
    eBook - ePub

    MongoDB Fundamentals

    A hands-on guide to using MongoDB and Atlas in the real world

    • Amit Phaltankar, Juned Ahsan, Michael Harrison, Liviu Nedov(Authors)
    • 2020(Publication Date)
    • Packt Publishing
      (Publisher)

    1. Introduction to MongoDB

    Overview
    This chapter will introduce you to MongoDB fundamentals, first defining data and its types, then exploring how a database solves data storage challenges. You will learn about the different types of databases and how to select the right one for your task. Once you have a clear idea about these concepts, we will discuss MongoDB, its features, architecture, licensing, and deployment models. By the end of the chapter, you will have gained hands-on experience using MongoDB through Atlas—the cloud-based service used to manage MongoDB—and worked with its basic elements, such as databases, collections, and documents.

    Introduction

    A database is a platform to store data in a way that is secure, reliable, and easily available. There are two types of databases used in general: relational databases and non-relational databases. Non-relational databases are often called as NoSQL databases. A NoSQL database is used to store large quantities of complex and diverse data, such as product catalogs, logs, user interactions, analytics, and more. MongoDB is one of the most established NoSQL databases, with features such as data aggregation, ACID (Atomicity, Consistency, Isolation, Durability ) transactions, horizontal scaling, and Charts, all of which we will explore in detail in the upcoming sections.
    Data is crucial for businesses—specifically, storing, analyzing, and visualizing the data while making data-driven decisions. It is for this reason that MongoDB is trusted and used by companies such as Google, Facebook, Adobe, Cisco, eBay, SAP, EA, and many more.
    MongoDB comes in different variants and can be utilized for both experimental and real-world applications. It is easier to set up and simpler to manage than most other databases due to its intuitive syntax for queries and commands. MongoDB is available for anyone to install on their own machine(s) or to be used on the cloud as a managed service. MongoDB's cloud-managed service (called Atlas) is available to everyone for free, whether you are an established enterprise or a student. Before we start our discussion of MongoDB, let us first learn about database management systems.
  • Get Programming with Node.js
    You want to start saving data from your application into a database, but you’re unsure which database to use. With Node.js, you can work with practically any common database, such as MySQL, PostgreSQL, Cassandra, Redis, and Neo4j. You can get a sense of the most supported and popular database management systems by exploring their associated packages on npm.
    MongoDB, however, offers a unique style of data storage that resembles JSON—a JavaScript-friendly format that may make working with databases easier for you as you delve into saving data with Node.js for the first time.

    13.1. Setting up MongoDB

    Storing data is arguably the most important part of application development. Without long-term storage, you’re limited in the way you can interact with your users. The data in every application you’ve built to this point disappeared each time you restarted the application. If data from a social network were to disappear every time a user closed his browser or every time you restarted that application, users would have to create new accounts and start from scratch.
    A database is an organization of your data designed for easy access and efficient changes made by your application. A database is like a warehouse: the more items you need to store, the happier you’ll be with an organized system that helps you find those items. Like a web server, your application connects to a MongoDB database and requests data.
    Throughout this unit, I discuss how to save information to a database for long-term storage. Your data will persist, even if the application is shut down.
    MongoDB is an open-source database program that organizes data by using documents. MongoDB documents store data in a JSON-like structure, allowing you to use key-value pairing to associate data objects with properties.
    This system of storage follows a familiar JavaScript syntax. Notice in figure 13.1
  • Mastering MongoDB 6.x

    1

    MongoDB – A Database for the Modern Web

    In this chapter, we will lay the foundations for understanding MongoDB. We will explore how it is a database designed for the modern web and beyond. Learning is as important as knowing how to learn in the first place. We will go through the references that have the most up-to-date information about MongoDB, for both new and experienced users.
    By the end of this chapter, you will have learned where MongoDB is best suited to be used and when it might be sub-optimal to use it. Learning about the evolution of MongoDB and the wider ecosystem will allow you to apply critical thinking when evaluating different database options early on in the software development life cycle.
    In this chapter, we will cover the following topics: 
    • SQL and MongoDB’s history and evolution
    • MongoDB from the perspective of SQL and other NoSQL technology users
    • MongoDB’s common use cases and why they matter
    • MongoDB’s configuration and best practices

    Technical requirements

    To sail smoothly through the chapter, you will need MongoDB version 5 installed or a free tier account in MongoDB Atlas The code that has been used for all of the chapters in this book can be found at https://github.com/PacktPublishing/Mastering-MongoDB-6.x .

    The evolution of SQL and NoSQL

    Structured Query Language  (SQL ) existed even before the World Wide Web (WWW ). Dr. E. F. Codd originally published a paper, A Relational Model of Data for Large Shared Data Banks , in June 1970, in the Association of Computer Machinery  (ACM ) journal, Communications of the ACM . SQL was initially developed at IBM by Chamberlin and Boyce, in 1974. Relational Software (now known as Oracle Corporation) was the first to develop a commercially available implementation of SQL, which was targeted at United States governmental agencies.
    The first American National Standards Institute  (ANSI
  • Mastering MongoDB 4.x
    eBook - ePub

    Mastering MongoDB 4.x

    Expert techniques to run high-volume and fault-tolerant database solutions using MongoDB 4.x, 2nd Edition

    Putting the SQL to NoSQL differences aside, it is users from columnar-type databases that face the most challenges. With Cassandra and HBase being the most popular column-oriented database management systems, we will examine the differences and how a developer can migrate a system to MongoDB. The different features of MongoDB for NoSQL developers are as follows:
    • Flexibility : MongoDB's notion of documents that can contain sub-documents nested in complex hierarchies is really expressive and flexible. This is similar to the comparison between MongoDB and SQL, with the added benefit that MongoDB can more easily map to plain old objects from any programming language, allowing for easy deployment and maintenance.
    • Flexible query model : A user can selectively index some parts of each document; query based on attribute values, regular expressions, or ranges; and have as many properties per object as needed by the application layer. Primary and secondary indexes, as well as special types of indexes (such as sparse ones), can help greatly with query efficiency. Using a JavaScript shell with MapReduce makes it really easy for most developers (and many data analysts) to quickly take a look at data and get valuable insights.
    • Native aggregation : The aggregation framework provides an extract, transform, load (ETL ) pipeline for users to extract and transform data from MongoDB, and either load it in a new format or export it from MongoDB to other data sources. This can also help data analysts and scientists to get the slice of data they need in performing data wrangling along the way.
    • Schema-less model : This is a result of MongoDB's design philosophy to give applications the power and responsibility to interpret the different properties found in a collection's documents. In contrast to Cassandra's or HBase's schema-based approach, in MongoDB, a developer can store and process dynamically generated attributes.
    Passage contains an image

    MongoDB's key characteristics and use cases

    In this section, we will analyze MongoDB's characteristics as a database. Understanding the features that MongoDB provides can help developers and architects to evaluate the requirements at hand and how MongoDB can help to fulfill them. Also, we will go over some common use cases from the experience of MongoDB, Inc. that have delivered the best results for its users.
  • SQL Pocket Primer
    eBook - ePub
    Before you decide to adopt one of the preceding databases, compare your list of requirements with each of these databases (and you might decide to adopt MySQL). If two of them are viable candidates, check for blog posts that contain a detailed comparison. If you decide to utilize an application that uses each of those two databases, remember that performance-related issues generally arise when there is a high volume of data and/or many simultaneous transactions.
    Now that you have an overview of some of the differences between RDBMSs and NoSQL databases, let’s take a closer look at MongoDB, which is the topic of the next section.

    What is MongoDB?

    MongoDB is a popular NoSQL database that supports NoSQL operations on data. As a quick reminder, in an earlier chapter, you learned that an RDBMS allows you to create databases and tables and then insert data into those tables. By contrast, MongoDB supports the creation of databases and collections, after which you can insert documents into the collections (discussed in more detail shortly).
    Features of MongoDB
    In addition to support for many standard query types, MongoDB offers the following features:
    • sharding
    • load balancing
    • scalability
    • schemas are optional
    • support for indexes
    Installing MongoDB
    There are two versions of MongoDB that you can install on your machine. The MongoDB community edition is downloadable: https://docs.mongodb.com/manual/installation/#mongodb-community-edition-installation-tutorials Note that on MacOS, you can use brew to install MongoDB. The MongoDB Enterprise edition is downloadable: https://docs.mongodb.com/manual/administration/install-enterprise/ In addition, you can use MongoDB with Docker (search online for tutorials and instructions).
    Launching MongoDB
    Launch the command mongo without arguments, which then launches a command shell and also connects to the URL mongod://127.0.0.1:27017 .
    The preceding URL is the default local server, and you’re connected to the local host through port 27017. Type the following command to find the location of the mongo executable:
  • Big Data Systems
    eBook - ePub

    Big Data Systems

    A 360-degree Approach

    • Jawwad Ahmed Shamsi, Muhammad Ali Khojaye(Authors)
    • 2021(Publication Date)
    MongoDB is a non-relational, open-source, NoSQL database, which relies on document storage to store data. This implies that all the data in MongoDB is stored in documents. MongoDB provides a few services of relational databases such as sorting, secondary indexing, and range queries.
    MongoDB is a scalable database which relies on scaling out. This means that more computing nodes can be added easily.
    1. Data Representation: As discussed, MongoDB is a document-style database. Document-style is analogous to the concept of row in RDBMS. Documents in MongoDB are stored in JavaScript Object Notation (JSON) format [140 ]. In MongoDB, a Collection is a group of documents. This is analogous to a table in RDBMS.
      Document Storage in MongoDB
      Example 7.7 (Document Storage in MongoDB).
      In this example, we will learn some of the valid and invalid styles of representing <key,value> pairs in MongoDB documents.
      {"Student" : "John, Smith"}.
      Here, the document contains a key ”student”, with a value ”John Smith”.
      Multiple <Key,Values>:
      Multiple keys in a document can also be included but they must be unique. For instance, following is a valid representation:
      {"Student" : "John, Smith", "City": "Cleveland"}
      Duplicate Keys:
      Duplicate keys are not allowed. For instance,
      {"Student" : "John, Smith", "Student": "John, Smith"}
      Case-Sensitive:
      Keys are case-sensitive. Therefore,
      {"Student" : "John, Smith", "student": "John, Smith"}
      are valid <key,value> pairs.
    2. Indexing and Sharding: MongoDB supports indexing of data for fast query processing. Documents are indexed according to keywords for faster access and retrieval.
    Understanding Sharding
    Example 7.8 (Understanding Sharding).
    In a DBMS, sharding (or index sharding) is the process of splitting a database across multiple machines. Sharding is the process of splitting the data into small chunks and storing them into partitions such that each partition stores a few chunks. The process is also called as partitioning
  • RDF Database Systems
    eBook - ePub

    RDF Database Systems

    Triples Storage and SPARQL Query Processing

    • Olivier Curé, Guillaume Blin(Authors)
    • 2014(Publication Date)
    • Morgan Kaufmann
      (Publisher)
    In a document store the values can be nested documents or lists, as well as scalar values. The nesting aspect is one important differentiator with the advanced key-value stores we just presented. The attribute names are not predefined in a global schema, but rather are dynamically defined for each document at runtime. Moreover, unlike RDBMS tuples, a wide range of values are authorized. A document stores data in tree-like structures and requires the data to be stored in a format understood by the database. In theory, this storage format can be XML, JSON, Binary JSON (BSON), or just about anything, as long as the database can understand the document’s internal structure. Several systems are available in that category with MongoDB certainly being the most popular and used in productions. Nevertheless, solutions such as CouchDB (Apache), MarkLogic (an enterprise-ready system that possesses all the features of a RDF store), and RavenDB are also active. MongoDB is an open-source, schema-free, document-oriented database using a collection-oriented storage. Collections are analogous to tables in a relational database. Each collection contains documents that can be nested in complex hierarchies and still support efficient query and index implementations. A document is a set of fields, each one being a key-value pair. A key is a string, and the value associated can be a basic type, a document, or an array of values. In addition, it allows efficient storage of binary data including large objects (e.g., photos and videos). MongoDB provides support for indexes and queries for fetching data. Indexing techniques rely on B+trees and support multikey and secondary indexes. Dynamic queries are also supported with automatic use of indices, like in most RDBMSs. Each query goes through an optimization phase before being executed. MongoDB also supports MapReduce techniques for complex aggregations across documents
  • Big Data and Hadoop- Learn by Example
    eBook - ePub
  • To store documents with efficiency a document and its metadata is combined and is therefore referred to as buffer first and is then written to disk sequentially. Hence, documents may be read by clients and the database (for e. g. indexing purposes, view-calculation) efficiently in one go.
  • MongoDB: MongoDB is also an open source project which is also called schema free database. It is written in C++ and owned by 10gen Inc. Its main motive is to fill the gap of traditional technology and latest one. It also provides solution for issues of traditional RDBMS with scalable key-value database. SourceForge.net, foursquare, the New York Times, the URL-shortener bit.ly and the distributed social network DIASPORA are the main users of MongoDB.
    1. Database and Collection: MongoDB databases reside on a MongoDB server that may host over one of such databases that are independent and keep separate by the MongoDB server. A database contains one or more collections of documents. So as to regulate access to the database a group of security credentials is also defined for databases.
      Collections within databases are mentioned by the MongoDB manual as “named by groupings of documents”. As MongoDB is schema-free the documents within a set may be heterogeneous although the MongoDB manual suggests to make “one database collection for every of your high-level objects”. Once the primary document is inserted into a database, a collection is created automatically and the document is inserted to this collection. Such an implicitly created collection gets organized with default parameters by MongoDB if individual values for choices like auto-indexing, pre-allocated disc space or size-limits are demanded, collections may also be produced explicitly by the “createCollection” command.
      db . createCollection (< name >, {< configuration parameters >})
      If need to create collection with name “mycoll” and 10,000,000 bytes of pre-allocated disk space and “no automatically generated” and indexed document-field _id:
      db . createCollection (“ mycoll “, {size :10000000, autoIndexId : false });
      MongoDB use convention of dot-notation which show any hierarchical namespace e.g. the collections wiki.articles, wiki.categories and wiki.authors residing under the namespace wiki. The MongoDB manual notes that “this is simply an organizational mechanism for the user and collection namespace is flat from the database's perspective”.
      Here is the sample database to represent MongoDB representation:
      { title : “ MongoDB”, last_editor : “192.51.223.42”, last_modified : new Date (“25/10/1985”), body : “ MongoDB is a …”, categories : [“ Database “, “ NoSQL “, “ Document Database “], reviewed : false }
      To insert such document in collection of MongoDB following command can be use:
  • Big Data and Hadoo - 2nd Edition
    eBook - ePub

    Big Data and Hadoo - 2nd Edition

    Fundamentals, tools, and techniques for data-driven success (English Edition)

    Text search : MongoDB includes a powerful text search feature that enables you to perform full-text search queries on text fields. It supports language-specific stemming, stop words, and text index optimization for efficient searching.
  • Transactions : MongoDB supports multi-document transactions, allowing you to perform multiple operations as a single atomic unit of work. Transactions ensure data consistency and integrity in complex operations involving multiple documents.
  • GridFS : MongoDB provides a built-in file system specification called GridFS for storing and retrieving large files. Actual files are stored within MongoDB. It allows you to split files into smaller chunks and store them as documents in MongoDB, enabling efficient storage and retrieval of large files. GridFS does not function like a traditional file system on your operating system (it does not organize files in directories, for example), it serves as a protocol and a set of conventions for storing and retrieving large files in a database.
  • Following are few examples of the operations available in MongoDB. It offers a comprehensive set of features and capabilities for data storage, retrieval, manipulation, and analysis:
    • To establish foreign keys and to establish connections between documents, MongoDB provides references that connect different documents. It does not connect these automatically. It can be set manually by _id field.
      { $ref : < collectionname > , $id : < documentid >[ , $db : < dbname >] }
    • The selection query of MongoDB refers as the query object. Find the parameter used to collect queries.
      db . < collection >. find ( { title : " MongoDB " ) ;
      Other than this lot of operators are also allowed. < fieldname >: {$ < operator >: < value >} < fieldname >: {$ < operator >: < value > , $ < operator >: value } // AND - junction The preceding table use operator with value to allow for selection. For selecting modulo following table is required.
    Index pages curate the most relevant extracts from our library of academic textbooks. They’ve been created using an in-house natural language model (NLM), each adding context and meaning to key research topics.
    Explore more topic indexes
    Explore more topic indexes
    1 of 6
    Explore more topic indexes
    1 of 4