Skip to Content

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.

MongoDB는 오픈소스 NoSQL 데이터베이스입니다. 비관계형 데이터베이스로서, 정형, 반정형 및 비정형 데이터를 처리할 수 있습니다. 비관계형 문서 지향 데이터 모델과 구조화되지 않은 쿼리 언어를 사용합니다.

MongoDB는 매우 탄력적이며 여러 유형의 데이터를 결합해 저장할 수 있습니다. 또한 기존 관계형 데이터베이스보다 더 많은 양의 데이터를 저장하고 처리합니다. MongoDB는 더 많은 데이터 유형을 수용할 수 있는 JSON(JavaScript Object Notation)의 바이너리 형식인 BSON으로 문서를 저장합니다.

MongoDB는 어떻게 작동할까요?

MongoDB는 기존 관계형 데이터베이스에서 사용되는 테이블과 행 대신, 컬렉션과 문서에 데이터 객체를 저장합니다. 컬렉션은 관계형 데이터베이스의 테이블에 상응하는 문서 집합으로 구성됩니다. 문서는 MongoDB의 기본 데이터 단위인 키-값 쌍으로 구성됩니다.

문서의 구조는 새 필드를 추가하거나 기존 필드를 삭제해 간단히 변경할 수 있습니다. 문서는 기본 키를 고유 식별자로 정의할 수 있으며, 값은 다른 문서, 배열 및 문서 배열 등의 다양한 데이터 유형이 될 수 있습니다.

MongoDB 텍스트 검색은 어떻게 작동할까요?

MongoDB의 주요 기능은 텍스트 검색으로, 특정 텍스트나 단어에 대한 문자열 필드를 쿼리할 수 있습니다.  텍스트 인덱스 또는 $text 연산자를 사용해 텍스트 검색을 수행할 수 있습니다.

텍스트 인덱스는 문자열이거나 문자열 요소의 배열일 수 있습니다. 텍스트 검색 쿼리를 수행하려면, 컬렉션에 텍스트 인덱스가 포함돼 있어야 합니다. 컬렉션에는 하나의 텍스트 인덱스만 존재하며, 단일 텍스트 인덱스는 여러 필드에 적용될 수 있습니다.

$text 연산자를 사용해 텍스트 인덱스가 있는 컬렉션에서 검색을 수행할 수도 있습니다. $text 연산자는 각 검색 문자열을 공백으로 토큰화하고, ‘–’와 ‘\’를 제외한 모든 구두점을 구분 기호로 처리합니다. 검색 문자열이 토큰화된 후 연산자는 토큰에 대해 논리 OR 연산을 수행합니다.

세 가지 MongoDB 쿼리 예시

MongoDB는 MongoDB 쿼리 언어(MQL)를 사용하여 데이터베이스에서 데이터를 가져옵니다. 문서의 생성, 읽기, 갱신 및 삭제에 CRUD 연산을 사용하는 SQL과 유사하게 작동하기 때문에 쉽게 사용할 수 있습니다. 함수 이름은 구문을 따릅니다.

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

다음은 실제 사용되는 모습을 보여주는 세 가지 예입니다.

삽입: 컬렉션에 새 문서를 만들거나 삽입합니다. 컬렉션이 없으면 새 컬렉션이 생성됩니다.

        db.collection.insertOne()은 하나의 문서를 컬렉션에 삽입합니다.

        db.collection.insertMany()는 컬렉션에 여러 문서를 한 번에 삽입합니다.

고객 컬렉션에 하나의 문서를 삽입하는 것은 다음과 같습니다:

        db.customer.insertOne (

        {

        firstname: “Jane”,

        lastname: “Mason”

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

        }

찾기: 문서 컬렉션을 쿼리합니다. 쿼리 필터와 기준을 적용하여 특정 문서를 찾을 수 있습니다.

        db.collection.find()

다음 코드는 고객 컬렉션의 모든 문서를 찾습니다:

        db.customer.find()

업데이트: 이렇게 하면 컬렉션의 기존 문서가 수정됩니다.

        db.collection.updateOne()

        db.collection.updateMany()

        db.collection.replaceOne()

고객 컬렉션에서 하나의 문서를 업데이트하는 방법은 다음과 같습니다:

        db.customer.updateOne(

        { firstname: “Jane” },

                       {

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

                        }

        )

MongoDB의 3가지 장점

유연성

MongoDB는 비정형 데이터 및 스토리지와 함께 작동하는 동적 스키마 아키텍처를 갖추고 있습니다. 데이터는 탄력적인 JSON 유형의 문서로 저장되기 때문에, 데이터베이스 스키마를 사전에 정의할 필요가 없으며 스키마를 다운타임 없이 동적으로 수정할 수 있습니다.

MongoDB의 BSON 데이터 형식을 사용하면, 한 컬렉션의 객체가 여러 다른 필드 집합을 가질 수 있으며 거의 모든 유형의 데이터 구조를 모델링하고 조작할 수 있습니다. 덕분에, MongoDB의 유연한 데이터베이스 모델은 비즈니스와 데이터 요구 사항이 변경될 때 특히 유용합니다.

샤딩

MongoDB는 샤딩(sharding)이라는 프로세스를 통해 수평 확장을 지원합니다. 샤딩은 대용량 데이터 세트에서 데이터를 분할하여 여러 서버에 분산 저장하는 기법입니다. 하나의 서버가 대용량 데이터를 처리할 수 없는 경우, 데이터 처리를 중단하지 않고 자동으로 분할 및 배포할 수 있습니다.

더 뛰어난 성능

MongoDB는 쿼리를 실행할 때 RAM에 데이터를 저장하여 더 빠른 데이터 액세스와 더 나은 성능을 제공합니다. 하드 디스크가 아니라 RAM에서 직접 데이터를 수집하므로 데이터 읽기 및 쓰기 속도가 더 빠릅니다. MongoDB는 또한 비관계형 데이터 구조이기 때문에 관계형 데이터베이스보다 적은 처리 능력으로 데이터를 검색하고 가져올 수 있습니다.

언제 MongoDB를 사용해야 할까요?

실시간 분석

NoSQL 데이터베이스인 MongoDB는 빅데이터(기존 관계형 데이터베이스로 처리하기에는 너무 방대한 양의 다양한 데이터)를 통합하고 처리하는 데 적합합니다.

MongoDB는 스키마가 없기 때문에 다양한 데이터 유형을 즉시 저장하고 액세스할 수 있습니다. MongoDB는 기본적으로 샤딩을 지원하기 때문에 여러 서버로 데이터를 수평 확장할 수도 있습니다. 또한 실시간 분석과 데이터 통합을 위해 수백 개의 데이터 소스를 단일 뷰로 병합하는 데 필요한 유연성을 제공합니다.

콘텐츠 관리

MongoDB의 구조화되지 않은 문서 모델은 이커머스 웹사이트, 온라인 게시물, 웹 콘텐츠 관리 시스템의 콘텐츠를 관리 및 제공하기 위한 탁월한 옵션입니다. 유연한 데이터 모델을 통해, 이미지, 텍스트, 비디오 및 메타데이터를 포함한 여러 유형의 콘텐츠를 쉽게 저장할 수 있습니다.

모든 관련 콘텐츠는 단일 문서에 저장되므로 새로운 기능과 속성을 쉽게 추가할 수 있습니다. MongoDB는 분석 후 향후 콘텐츠 개발의 지침으로 삼을 수 있는 댓글(comments) 같은 사용자 생성 콘텐츠를 저장하는 데에도 사용할 수 있습니다.

네 가지 MongoDB 질문에 대한 답변

MongoDB와 MySQL은 어떤 차이가 있나요?

MySQL은 Oracle이 관리하는 관계형 데이터베이스 관리 시스템(RDBMS)입니다. 사전 정의된 테이블과 행으로 데이터를 표현하는 구조적 쿼리 언어(SQL)를 사용합니다. MySQL은 관련 테이블에서 데이터를 가져오는 데 JOIN 연산자가 필요합니다. MySQL은 효과적인 복제나 샤딩을 허용하지 않습니다.

MongoDB는 MongoDB, Inc.에서 유지 관리하는 오픈 소스 교차 플랫폼 데이터베이스입니다. 현대 소프트웨어 애플리케이션의 데이터 요구 사항을 처리하는 것을 목표로 구축된 문서 기반 데이터베이스입니다. MongoDB는 JavaScript를 쿼리 언어로 사용하고 데이터를 JSON 문서로 표시합니다. 사전 정의된 스키마가 필요하지 않습니다. 동일한 컬렉션의 문서들이 다른 구조를 가질 수 있다는 의미입니다.

MongoDB가 MySQL보다 빠른가요?

MySQL은 JOIN 연산을 사용해 여러 테이블에서 관련 데이터에 액세스하고 쿼리합니다. 이렇게 하면 데이터 중복이 최소화되지만 성능에 영향을 미칠 수 있는 수백만 건의 읽기 및 쓰기가 발생합니다.

MongoDB의 문서 모델은 관련 데이터를 함께 저장하므로 MySQL보다 빠르게 문서를 가져올 수 있습니다. MongoDB는 슬레이브 및 마스터 복제를 사용해 MySQL보다 훨씬 빠르게 대량의 비정형 데이터를 처리할 수 있습니다.

언제 MySQL 대신 MongoDB를 사용해야 할까요?

MongoDB를 선택할지, MySQL을 선택할지는 특정 사용 사례와 비즈니스 요구 사항에 따라 다르지만, MongoDB는 MySQL대비 몇 가지 이점을 제공합니다. 그 혜택은 다음과 같습니다:

  • 문서 지향 설계: MongoDB는 비구조적 쿼리 언어(NoSQL) 데이터베이스이기 때문에 데이터를 관계형 형식이 아닌 문서로 저장합니다. 이 때문에 실제 비즈니스 시나리오에 더 유연하게 적용될 수 있습니다. 반대로 MySQL의 관계형 데이터 스키마는 사전 정의되어 있어 경직되고 유연하지 못합니다.
  • 로드 밸런싱: MongoDB는 샤딩을 통해 로드 밸런싱을 지원하므로 데이터를 수평으로 확장할 수 있습니다. 샤딩은 데이터를 여러 MongoDB 인스턴스와 서버로 분할하여 하드웨어에 장애가 발생한 경우 로드의 균형을 조정하거나 성능을 향상할 수 있습니다.
  • 임시 쿼리: MongoDB는 필드, 범위 쿼리 및 정규식으로 검색하는 임시 쿼리를 지원합니다. 쿼리는 문서 내의 특정 필드를 반환할 수 있습니다.

가장 적합한 데이터베이스:  MySQL 또는 MongoDB?

MongoDB와 MySQL은 본질적으로 다른 데이터베이스 관리 시스템이지만 각기 탁월한 역량을 발휘하는 분야가 있습니다.

MongoDB는 조직이 애플리케이션을 더 빠르게 구축할 수 있도록 하며 다양한 유형과 대용량 데이터를 처리하는 데 적합합니다. 높은 데이터 가용성, 스키마 유연성, 신속한 확장 기능, 빅데이터 및 분석 요구 지원 역량이 필요할 때 MongoDB를 사용합니다.

데이터 스키마가 안정적이고 비정형 데이터를 저장할 필요가 없는 경우에는 MySQL이 더 나은 선택입니다. 높은 트랜잭션 속도, 참조 무결성과 함께 제공되는 보안이 필요하거나, 변경 가능성이 없는 데이터 구조가 있는 경우 MySQL을 사용하는 것이 좋습니다.

퓨어스토리지로 오픈소스 DB 워크로드 가속화

페일오버와 수평 확장 역량을 갖춘 MongoDB는 현대의 애플리케이션을 위해 구축된 오픈 소스 데이터베이스입니다. MongoDB의 문서 데이터 모델은 JSON을 지원하고 객체 지향 언어에 자연스럽게 매핑되어 개발을 간소화합니다. 개발자는 쿼리 언어를 쉽게 배우고 사용할 수 있습니다.

초고속 파일 및 오브젝트 데이터 통합을 위한 업계 최고의 올플래시 스토리지 솔루션인 퓨어스토리지 플래시블레이드(FlashBlade®)로 스토리지를 현대화하세요. 플래시블레이드가 제공하는 혜택:

  • 민첩한 스케일-아웃 아키텍처: 플래시블레이드(FlashBlade)는 최고의 성능과 풍부한 데이터 서비스로 수백억 개의 파일 및 오브젝트를 처리합니다.
  • 간소화된 워크로드 통합: 퓨어1(Pure1)®으로 플래시블레이드(FlashBlade) 구축, 업데이트 및 관리
  • 올플래시 성능: 플래시블레이드 초고속 파일 및 오브젝트 스토리지의 일관된 다차원적 성능을 통한 대용량 데이터 처리 및 병렬 처리 확보
연락처
질문하기

퓨어스토리지 제품이나 인증 관련 질문이나 코멘트가 있으신가요?   저희가 도와드립니다.

데모 예약

라이브 데모를 예약하고 퓨어스토리지가 데이터를 어떻게 강력한 결과로 전환해주는지 직접 확인해 보세요. 

연락하기: +82 2 6001-3330

언론홍보팀:  pr@purestorage.com

 

퓨어스토리지코리아 주소

30F 아셈타워,

517 영동대로,

강남구, 서울

대한민국

korea@purestorage.com

닫기
지원하지 않는 브라우저입니다.

오래된 브라우저는 보안상 위험을 초래할 수 있습니다. 최상의 경험을 위해서는 다음과 같은 최신 브라우저로 업데이트하세요.