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

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

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!

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

AWS Security LIVE!

Hosted by security experts, AWS Security LIVE! showcases AWS Partners tackling real-world security challenges. Join live and get your security questions answered.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️