DEV Community

Mark Kop
Mark Kop

Posted on • Edited on

2

Fullstacking: Setting up MongoDB

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

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (1)

Collapse
 
arojunior profile image
Junior Oliveira

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!

Retry later
Retry later