compare","metadata":{}}]}}]},"metadata":{"auth":{},"testAttributes":{}},"context":{"page":{"locale":null,"site":null,"pageUrl":"https://aws.amazon.com/compare/the-difference-between-cassandra-and-mongodb/","targetName":null,"pageSlotId":null,"organizationId":null,"availableLocales":null},"environment":{"stage":"prod","region":"us-east-1"},"sdkVersion":"1.0.115"},"refMap":{"manifest.js":"289765ed09","what-is-header.js":"251923df8a","what-is-header.rtl.css":"ccf4035484","what-is-header.css":"ce47058367","what-is-header.css.js":"004a4704e8","what-is-header.rtl.css.js":"f687973e4f"},"settings":{"templateMappings":{"category":"category","headline":"headline","primaryCTA":"primaryCTA","primaryCTAText":"primaryCTAText","primaryBreadcrumbText":"primaryBreadcrumbText","primaryBreadcrumbURL":"primaryBreadcrumbURL"}}}

What’s the Difference Between Cassandra and MongoDB?


Apache Cassandra and MongoDB are two NoSQL databases that store data in a non-tabular format. Cassandra is an early NoSQL database with a hybrid design between a tabular and key-value store. It’s designed to store data for applications that require fast read and write performance. In contrast, MongoDB is a document database built for general-purpose usage. It has a flexible data model that allows you to store unstructured data in an optimized JSON format called Binary JSON, or BSON. The MongoDB database provides full indexing support and replication with rich and intuitive APIs. \n

Read about Apache Cassandra » \n

Read about MongoDB »","id":"seo-faq-pairs#whats-the-difference-between-cassandra-mongodb","customSort":"1"},"metadata":{"tags":[{"id":"seo-faq-pairs#faq-collections#cassandra-vs-mongodb","name":"cassandra-vs-mongodb","namespaceId":"seo-faq-pairs#faq-collections","description":"

cassandra-vs-mongodb","metadata":{}}]}},{"fields":{"faqQuestion":"What are the similarities between Cassandra and MongoDB?","faqAnswer":"

Apache Cassandra and MongoDB both belong to the NoSQL database group. NoSQL databases can store structured, unstructured, and semi-structured data without a database schema. \n

Data storage in NoSQL databases isn’t constrained by the tabular format and relationships between tables, unlike in a traditional relational database management system. You can freely partition and replicate data across multiple nodes to scale efficiently.  \n

Additionally, Cassandra and early versions of MongoDB are open source. This means you can download the source code of these NoSQL databases and configure them as you like. \n

Facebook developed Cassandra and then released it as an open-source project with Apache. MongoDB was developed by a small group of developers under MongoDB, Inc. All versions of MongoDB released before October 16, 2018 are available under the GNU Affero General Public License. \n

Read about NoSQL » \n

Read about open source »","id":"seo-faq-pairs#what-are-similarities-between-cassandra-and-mongodb","customSort":"2"},"metadata":{"tags":[{"id":"seo-faq-pairs#faq-collections#cassandra-vs-mongodb","name":"cassandra-vs-mongodb","namespaceId":"seo-faq-pairs#faq-collections","description":"

cassandra-vs-mongodb","metadata":{}}]}},{"fields":{"faqQuestion":"Data model differences: Cassandra vs. MongoDB","faqAnswer":"

Although MongoDB and Apache Cassandra are both NoSQL databases, they store and manage data differently. \n

Cassandra \n

Cassandra stores data as key-value stores. It allows you to define tables with rows and columns, but the tabular structure isn’t used in actual storage. Instead, it uses the wide column-oriented database model, so each row in the table can have a different set of columns. \n

You can group columns into column families based on their data type or usage. Every row has a primary key that you can use to quickly read data from Cassandra. \n

Apache Cassandra table structure can be visualized in the following example. \n

\n \n \n \n \n \n
Customer id 1 \n

Column - Name \n

Column - Country \n

  \n \n
  \n

Value - John Doe \n

Value - United States \n

  \n \n
Customer id 2 \n

Column - Name  \n

Column - Age \n

Column - Email \n \n

  \n

Value - Jane Doe \n

Value - 35 \n

Value - [email protected] \n \n \n \n

MongoDB \n

In contrast, MongoDB stores data without a schema, using an optimized Binary JSON (BSON) format. It can store several data types in a single document, similar to JSON objects, and then serialize it with BSON. \n

MongoDB organizes documents into collections that can contain data with different structures. Its data model is flexible and can handle large volumes of unstructured data. \n

The following is an example of the customer data in MongoDB. \n

\n \n \n

customers:[

{

  customer_id: \"1\",

  name: “John Doe”,

  country: \"United States\"

},

{

  customer_id: \"2\",

  age: “35”

  email: \"[email protected]\"

}] \n \n \n","id":"seo-faq-pairs#data-model-differences","customSort":"3"},"metadata":{"tags":[{"id":"seo-faq-pairs#faq-collections#cassandra-vs-mongodb","name":"cassandra-vs-mongodb","namespaceId":"seo-faq-pairs#faq-collections","description":"

cassandra-vs-mongodb","metadata":{}}]}},{"fields":{"faqQuestion":"Architectural differences: Cassandra vs. MongoDB","faqAnswer":"

Due to differences in their data models, Cassandra and MongoDB implement several database features differently. \n

Basic unit of storage \n

In Cassandra, Sorted String Tables (SSTables) are the basic unit of storage used to persist data on disk. An SSTable is a file that contains a sorted set of key-value pairs for a particular column family (table) and partition. SSTables are immutable, which means that once they’re written, they can’t be modified.  \n

In MongoDB, the basic unit of storage is a document. A document is a set of key-value pairs where the keys are strings and the values can be of various types. For example, values can be other documents, arrays, strings, numbers, dates, and Boolean values. Documents are stored in collections. \n

Query language \n

A query language is the statements you use to insert and retrieve data from the database. \n

Cassandra Query Language (CQL) is the query language that you use on Cassandra. While it has a similar syntax and structure to SQL, Apache has developed CQL to work with the column-family data model. \n

On the other hand, MongoDB uses MongoDB Query Language (MQL), which has similar commands as Node.js. MQL supports create, read, update, and delete (CRUD) operations. You can write MQL commands on the MongoDB Shell. \n

Indexing \n

Indexing is a technique used in databases to improve the speed and efficiency of data retrieval operations. It involves creating a data structure that maps the values of one or more columns in a database table to the physical location of the corresponding data on disk. \n

Cassandra supports two types of indexes: \n