Fullstacking: Setting up MongoDB
(Source/Credits: https://dev.to/heymarkkop/fullstacking-setting-up-mongodb-3oed)
This is part of a full-stack challenge. Let's start by trying to make all layers working by themselve...
This is part of a full-stack challenge.
Let's start by trying to make all layers working by themselves: React Native
, NodeJS
+ KoaJS
and MongoDB
.
In this tutorial we'll be setting up MongoDB
following these instructions on Ubuntu 18.04
MongoDB
Import the MongoDB public GPG Key:
wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -
Create a list file:
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list
Reload the local package database
sudo apt update
Install the latest stable version
sudo apt-get install -y mongodb-org
Start MongoDB
sudo service mongod start
Check log
cat /var/log/mongodb.log
Stop and Restart commands
sudo service mongod stop
sudo service mongod restart
Run mongo shell to connect to a MongoDB instance on default port 27017:
mongo
or mongo --port 27017
Display the database you are using
db
(returns the default database 'test')
Insert one object in the collection
db.collection.insertOne({ title: "Stampler" })
Query/Select it
db.collection.find({})
or
db.collection.find({ title: "Stampler"})
That's it. The next step is to make so NodeJS can query objects in our MongoDB instance. But before we'll set up React Native
and NodeJS
+ KoaJS
.
Feel free to comment below or hit me on twitter @HeyMarkKop
Comments section
arojunior
•May 1, 2024
Hey Mark, I really advise you to use Docker for local databases. It's not usual to have databases installed locally in development machines.
Good luck!