Skip to Content

What Is MongoDB?

MongoDB is an open source NoSQL database. As a non-relational database, it can process structured, semi-structured, and unstructured data. It uses a non-relational, document-oriented data model and a non-structured query language.

MongoDB is highly flexible and enables you to combine and store multiple types of data. It also stores and handles larger amounts of data than traditional relational databases. MongoDB uses a document storage format called BSON, which is a binary form of JSON (JavaScript Object Notation) that can accommodate more data types.

How Does MongoDB Work?

MongoDB stores data objects in collections and documents instead of the tables and rows used in traditional relational databases. Collections comprise sets of documents, which are equivalent to tables in a relational database. Documents consist of key-value pairs, which are the basic unit of data in MongoDB.

The structure of a document can be changed by simply adding new fields or deleting existing ones. Documents can define a primary key as a unique identifier, and values can be a variety of data types, including other documents, arrays, and arrays of documents.

How Does MongoDB Text Search Work?

A key feature of MongoDB is the text search, which can query string fields for specific text or words. A text search can be performed using a text index or the $text operator.

A text index can either be a string or an array of string elements. To perform a text search query, the collection must contain a text index. A collection can only have one text index, and a single text index can be applied to multiple fields.

A search can also be performed on a collection with a text index using the $text operator. The $text operator tokenizes each search string with white space and treats all punctuation except for “–” and “\” as delimiters. After the search string is tokenized, the operator performs the logical OR operation on the tokens.

Three MongoDB Query Examples

MongoDB uses MongoDB Query Language (MQL) to retrieve data from the database. It’s easy to use and works in a way that’s similar to SQL with CRUD operations for creating, reading, updating, and deleting documents. Function names follow the syntax:

        <database>.<collection_name>. <operation>.

The following are three examples that demonstrate this in practice:

INSERT: Create or insert a new document into a collection. If the collection does not exist, a new collection will be created.

        db.collection.insertOne() inserts one document into a collection.

        db.collection.insertMany() inserts multiple documents into a collection at once.

Here’s what inserting one document into the customer collection looks like:

        db.customer.insertOne (

        {

        firstname: “Jane”,

        lastname: “Mason”

        Address: “232 Petunia Drive, Atlanta, GA, 30311”

        }

FIND: This queries a collection of documents. Query filters and criteria can be applied to find specific documents.

        db.collection.find()

The following code finds all the documents in the customer collection:

        db.customer.find()

UPDATE: This modifies existing documents in a collection.

        db.collection.updateOne()

        db.collection.updateMany()

        db.collection.replaceOne()

Here’s how you’d update one document in the customer collection:

        db.customer.updateOne(

        { firstname: “Jane” },

                       {

                                $set: { “address”, “5 Lavender Ave, Atlanta, GA, 30311”}

                        }

        )

Top Three Advantages of MongoDB

Flexibility

MongoDB has a dynamic schema architecture that works with non-structured data and storage. Because data is stored in flexible, JSON-like documents, the database schema doesn’t have to be predefined and schemas can be modified dynamically without causing downtime.

With MongoDB’s BSON data format, objects in one collection can have different sets of fields, and almost any type of data structure can be modeled and manipulated. For this reason, MongoDB’s flexible database model is especially beneficial as business and data requirements change.

Sharding

MongoDB offers horizontal scaling through a process called sharding. Sharding divides data from a large data set and distributes it across multiple servers. If one server can’t handle a large load of data, it can be automatically divided and distributed without interrupting data processing.

Greater Performance

MongoDB stores data in RAM for faster data access and greater performance when executing queries. It collects data directly from RAM rather than the hard disk, making data reads and writes faster. MongoDB’s non-relational data structure also means that it requires less processing power to search and retrieve data than a relational database.

When Should You Use MongoDB?

Real-Time Analytics

As a NoSQL database, MongoDB is a good choice for integrating and processing big data (i.e., enormous amounts of diverse data too large to be processed by traditional relational databases).

Because MongoDB is schemaless, various data types can be stored and accessed on the fly. MongoDB’s built-in support for sharding also allows it to scale data horizontally across multiple servers. In addition, it provides the flexibility needed to merge hundreds of data sources into a single view for real-time analytics and data integration.

Content Management

MongoDB’s non-structured document model makes it an excellent option for content management and delivery of e-commerce websites, online publications, and web content management systems. Its flexible data model makes it easy to store several types of content, including images, text, and video, as well as metadata.

All related content is stored in a single document, making it easy to add new features and attributes. MongoDB can also be used to store user-generated content like comments, which can be analyzed and used to guide the development of future content.

Four MongoDB Questions Answered

What Is MongoDB vs. MySQL?

MySQL is a relational database management system (RDBMS) maintained by Oracle. It uses a structured query language (SQL), which represents data in predefined tables and rows. MySQL requires the JOIN operator to retrieve data from related tables. MySQL doesn’t allow for effective replication or sharding.

MongoDB is an open source cross-platform database maintained by MongoDB, Inc. It’s a document-based database that aims to handle the data demands of modern software applications. MongoDB uses JavaScript as the query language and represents data as JSON documents. It doesn’t require a predefined schema, which means that documents in the same collection can have different structures.

Is MongoDB Faster than MySQL?

MySQL uses JOIN operations to access and query related data across multiple tables. While this minimizes data duplication, it results in millions of reads and writes that can affect performance.

MongoDB’s document model stores related data together, allowing it to retrieve documents faster than MySQL. Using slave and master replication, MongoDB can process large amounts of unstructured data much faster than MySQL.

When Should You Use MongoDB Instead of MySQL?

Whether you choose MongoDB or MySQL will depend on your specific use cases and business needs, but MongoDB offers some advantages over MySQL. These include:

  • Document-oriented design: Because MongoDB is a NoSQL database, it stores data as documents instead of in a relational format. This makes it more flexible and adaptable to real-world business scenarios. In contrast, MySQL’s relational data schema is predefined, making it rigid and inflexible.
  • Load balancing: MongoDB supports load balancing through sharding, which enables data to scale horizontally. Sharding can split data across multiple MongoDB instances and multiple servers to balance the load in the event of a hardware failure or to enhance performance.
  • Ad hoc queries: MongoDB supports ad hoc queries with searches by field, range queries, and regular expressions. Queries can return specific fields within a document.

Which Database Is Best: MySQL or MongoDB?

MongoDB and MySQL are inherently different database management systems, but both excel in specific scenarios.

MongoDB allows organizations to build applications faster and is suitable for handling various types and large amounts of data. Use MongoDB when you need high data availability, schema flexibility, the ability to scale out quickly, or the ability to support big data and analytical needs.

MySQL is a better choice if your data schema is stable and you don’t need to store unstructured data. Use MySQL if you require a high transaction rate, the security that comes with referential integrity, or if you have a data structure that isn’t likely to change.

Accelerate Open Source Database Workloads with Pure

With automatic failover and horizontal scaling, MongoDB is an open source database built for modern applications. Its document data model supports JSON and maps naturally to object-oriented languages, simplifying development. Its query language is easy for developers to learn and use.

Modernize your storage with Pure Storage® FlashBlade®, the industry's most advanced all-flash storage solution for consolidating fast file and object data. FlashBlade offers:

  • Agile scale-out architecture: FlashBlade handles tens of billions of files and objects with maximum performance and rich data services.
  • Simplified workload consolidation: Deploy, update, and manage FlashBlade with Pure1®.
  • All-flash performance: Gain massive throughput and parallelism with consistent multidimensional performance through FlashBlade fast file and object storage.

こちらの資料もご覧ください!

12/2024
導入事例:株式会社 JSOL|ピュア・ストレージ
総合的な IT サービスの提供で定評のある株式会社 JSOL は、VDI のニーズ急増によるストレージの諸課題の抜本的な解決策としてピュアのオールフラッシュ・ストレージ FlashArray を導入し、ストレージ I/O の高速化をはじめとする大幅な性能の向上に成功しています。
導入事例
4 ページ
ご相談・お問い合わせ
ご質問・ご相談

ピュア・ストレージ製品および認定についてのご質問・ご相談を承っております。ご連絡をお待ちしております。

デモのご用命

ライブデモのご用命を承っております。ピュアがいかにしてデータを成果に変えるお手伝いができるかをご説明します。 

ピュア・ストレージ・ジャパン株式会社

〒100-0014 東京都千代田区永田町 2 丁目 10-3 東急キャピトルタワー 12 階

 

一般: info-japan@purestorage.com

メディア: pr-japan@purestorage.com

03-4563-7443(総合案内)

閉じる
このブラウザは現在サポートされていません。

古いブラウザには、セキュリティ・リスクが存在する場合があります。ピュア・ストレージの Web サイトをより快適にご利用いただけるよう、最新のブラウザにアップデートしてください。