0
0
DynamoDBquery~5 mins

DynamoDB vs MongoDB vs Cassandra

Choose your learning style9 modes available
Introduction

These are three popular databases used to store and manage data. Understanding their differences helps you pick the right one for your needs.

When you need a fast and scalable database for web apps with simple key-value access.
When you want flexible document storage with rich querying options.
When you need to handle very large amounts of data across many servers with high availability.
Syntax
DynamoDB
No single syntax applies as these are different database systems with their own query languages and APIs.

DynamoDB uses a key-value and document data model with AWS SDKs.

MongoDB uses a JSON-like query language for documents.

Examples
This fetches a music record by artist and song title in DynamoDB.
DynamoDB
DynamoDB: GetItem operation to fetch an item by primary key

aws dynamodb get-item --table-name Music --key '{"Artist": {"S": "No One You Know"}, "SongTitle": {"S": "Call Me Today"}}'
This finds users older than 25 in MongoDB.
DynamoDB
MongoDB: Find documents where age is greater than 25

db.users.find({ age: { $gt: 25 } })
This retrieves all user records in Cassandra using CQL (Cassandra Query Language).
DynamoDB
Cassandra: Select all rows from users table

SELECT * FROM users;
Sample Program

This creates a users table in Cassandra, inserts two users, and selects all users.

DynamoDB
-- Sample CQL query for Cassandra
CREATE TABLE users (
  id UUID PRIMARY KEY,
  name text,
  age int
);

INSERT INTO users (id, name, age) VALUES (uuid(), 'Alice', 30);
INSERT INTO users (id, name, age) VALUES (uuid(), 'Bob', 25);

SELECT * FROM users;
OutputSuccess
Important Notes

DynamoDB is fully managed by AWS and scales automatically.

MongoDB is document-oriented and good for flexible schemas.

Cassandra is designed for high availability and large scale across many servers.

Summary

DynamoDB is best for simple key-value access with automatic scaling.

MongoDB offers flexible document storage and rich queries.

Cassandra excels at handling huge data with high availability.