Swiftorial Logo
Home
Swift Lessons
Matchups
CodeSnaps
Tutorials
Career
Resources

Popular NoSQL Databases

1. MongoDB

MongoDB is one of the most popular NoSQL databases. It is document-oriented, which means it stores data in JSON-like documents with dynamic schemas. This flexibility allows developers to adapt to changing requirements easily.

Example:

In MongoDB, a document might look like this:

{ "name": "John Doe", "age": 30, "city": "New York" }

Documents are grouped into collections, which are analogous to tables in relational databases.

2. Cassandra

Apache Cassandra is designed for high availability and scalability. It uses a wide-column store model, allowing for efficient storage and retrieval of large amounts of data across many servers.

Example:

A simple Cassandra table might be defined with the following CQL (Cassandra Query Language):

CREATE TABLE users (username TEXT PRIMARY KEY, email TEXT, age INT);

This table allows for quick lookups based on the username.

3. Redis

Redis is an in-memory key-value store known for its speed and performance. It supports various data structures such as strings, hashes, lists, sets, and more, making it versatile for different use cases.

Example:

Storing and retrieving a simple value in Redis can be done with:

SET user:1000 "John Doe"
GET user:1000
"John Doe"

4. Couchbase

Couchbase is another document-oriented NoSQL database that combines the benefits of key-value and document databases. It allows for flexible data modeling and querying capabilities using SQL-like syntax.

Example:

In Couchbase, you can query documents using N1QL:

SELECT name FROM `bucket-name` WHERE age > 25;

This retrieves all names from a specific bucket where the age is greater than 25.

5. DynamoDB

Amazon DynamoDB is a fully managed NoSQL database service that provides fast and predictable performance with seamless scalability. It is a key-value and document store designed for high availability and fault tolerance.

Example:

Creating a table in DynamoDB can be done using the AWS Management Console or through AWS CLI:

aws dynamodb create-table --table-name Users --attribute-definitions AttributeName=username,AttributeType=S --key-schema AttributeName=username,KeyType=HASH --billing-mode PAY_PER_REQUEST

Conclusion

NoSQL databases offer various options tailored to different application needs, from document stores like MongoDB to key-value stores like Redis. Understanding the characteristics and use cases of each can help developers choose the right database for their projects.