Winntana Beyene
3 min readMay 4, 2019

MongoDb Tips

What is MongoDB ??

Well, if you’re new to this database thing , you should really be looking into MongoDb , its easy to grasp , it’s schema-less (you don’t need a defined structure for the data before storing it) , and a very efficient database management system.

Mongo is an open source DBMS and it uses a document- oriented database model that supports various forms of data.It stores data in JSON-like objects.It’s also one of many non-relational database technologies that came around in the mid — 2000s under the NoSQL banner for use in big data apps.

How to install :

[For Mac Users]

Open your bash & run

brew install mongodb

And as simple as that you have completed the process of installing this amazing DBMS.

Once you have installed mongodb you should see the something similar to the following in your terminal:

To have launched start mongodb now and restart at login:
brew services start mongodb
Or, if you don't want/need a background service you can just run:
mongod --config /usr/local/etc/mongod.conf

Either option is great , but I usually prefer just having it running in my background which is why I would suggest running the brew command , but it is perfectly fine to run the second command each time you need it.

Now that you have installed it properly , let’s move into the shell.

By the running the ```mongo``` program you can start the MongoDB shell, which will look like the following:

Once you have mongo running, you can start entering your commands.

COMMAND TIME !!!

To access the available databases, you can run the command :

show databases

To access a collection in current database, you run the command :

show collections 

To create a collection in the current database, you run the command:

db.createCollection()

To list objects that have been added to a collection , you run the command:

db.[‘collection-name’].find()

To remove all entries from a collection, you run the command:

db.['collection-name'].remove({})

Key-Terms:

field:

A name-value pair in a document. A document has zero or more fields. Fields are SIMILAR to columns in relational databases.

document:

A record in a MongoDB collection is basically called a document. The document, will consist of field name and values.

CustomerID and 11 is one of the key value pair’s defined in the document.

_id:

This is a field required in every MongoDB document. The _id field represents a unique value in the MongoDB document. The _id field is like the document’s primary key. If you create a new document without an _id field, MongoDB will automatically create the field.

collection:

This is a grouping of MongoDB documents. A collection is the equivalent of a table which is created in any other RDMS. A collection only exists within a single database.

Over all MongoDb is FREEEEEEEE!!!

Hope you gain just a little more confidence in wanting to join with us on the mongoDb team!!!

Sources:

https://searchdatamanagement.techtarget.com/definition/MongoDB
https://www.mongodb.com/