Welcome to the Document Stores tutorial! In this lesson, we'll dive into the world of NoSQL databases, focusing on document-based stores like MongoDB, CouchDB, and Firebase. Let's embark on a journey to learn about this exciting alternative to traditional SQL databases!
Document stores are NoSQL databases that use JSON-like documents with dynamic schemas. Unlike SQL databases, which have fixed schemas, document stores allow each document to have its own structure. This makes them ideal for handling complex, semi-structured, and unstructured data.
MongoDB is one of the most popular document stores. Let's install it and create our first database.
// Install MongoDB Community Server
curl -fsSL https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
sudo apt-get update
sudo apt-get install -y mongodb-org
// Start MongoDB service
sudo systemctl start mongod
sudo systemctl enable mongod
// Verify installation
mongo --versionNow, let's create a database called "myProject" and add a document:
mongo
> use myProject
> db.createCollection("users")
> db.users.insertOne({ name: "John Doe", age: 30 })To see the document we've just created, let's run a simple find operation:
> db.users.find()This will return the following output:
{ "_id" : ObjectId("604727b826471634d7e36d6e"), "name" : "John Doe", "age" : 30 }You've just created your first document in MongoDB!
What is a key difference between SQL databases and document stores?
Stay tuned for the next part of our Document Stores tutorial, where we'll delve deeper into MongoDB, learn about advanced features, and explore another popular document store, Firebase! 🚀