DEV Community

vblaha
vblaha

Posted on

MongoDB-A Less Goofy Way to Push

MongoDB-A Less Goofy Way to Push

skating

Anyone with a skating background reels at the word. Mongo. Thankfully, tech developers have managed to take back the word and give it some due respect. The history of MongoDB is as roundabout as the skate practice. Developers working towards an open source platform called Babble, (which would have resembled current-day Google Apps), had to build their own database to accommodate their project. Babble didn't quite have enough user interest, but MongoDB (short for humongous) filled the niche for a database model with flex, expanding as needed with minimal changes. So with that history, it becomes easier to understand how other splinter programs like Mongoose, can riff off of MongoDB and enhance its properties. Mongo is easy to use with Javascript notation and highly scalable to growing data, making it a key component of the MERN stack(Mongo, Express, React, and Node). So let's take a closer look at some of the ways you can use dat DB!

MongoDB doesn't use a query structure-instead, data is stored in BSON (binary JSON format). With Mongo, one server can hold multiple databases, and within the databases, collections are stored.Collections are sort of like folders that hold multiple documents(one document is one record of data). You can have multiple collections per database, and multiple documents per collection. Mongo builds these collections as objects.

Once stored, Mongo assigns a unique ObjectID to each document. MongoDB will create whatever it is told to, often producing duplicates or other unintended erroneous information, since MongoDB is run in the command line. MongoDB uses two separate terminal windows, one as the shell(mongod) and one as the client(mongo). Mongo takes in files and manages them for us. We use client mongo to communicate with the shell(mongod) by use of queries, or commands that we give to mongo.

user info:
{
name: "Veronica",
age: "32",
status: "Queen",
groups: ["3 Amigas","Coding Bootcamp","GDI"]
}

Now let's build the squad...
{
name:"Beltriz",
age: "29",
status: "Queen",
groups: ["3 Amigas","MOOC land", "GDI"]
}

{ name: "Sofia",
age: "28",
status: "Queen",
groups: ["3 Amigas", "GDI", "MOOC land"]
}

Now we've built a collection of documents to be stored in our database, complete with an object id. We can call these objects and manipulate data through mongo, our second terminal window.

While Mongo can be written in the shell, it is tedious and joining different collections together without a UI has challenges, so using an ODM (Object Document Mapper) in tandem with MongoDB expands functionality and reduces our headache factor when managing databases. So there you have it, our simple, beautiful DB, which is nothing like the ugly skate scoot, but arguably as painful to do without a code editor.

Check out my post on Mongoose and client UIs here to learn more, and thanks for viewing! I welcome feedback and comments for expansion and improvement.

Top comments (0)