Path: /usr/local/var/log/mongodb/mongo.log The default configuration for MongoDB is this: systemLog: You can choose to either launch MongoDB once and have it running forever as a background service in your computer (the thing I prefer), or you can run it just when you need it, by running the latter command. Or, if you don't want/need a background service you can just run: The installation tells us this: To have launchd start mongodb now and restart at login:
The instructions were not too long or complicated, assuming you know how to use the terminal and how to install Homebrew. I use a Mac, so the installation instructions in this tutorial refer to that operating system. You could use one of the many cloud providers that offer access to a MongoDB instance, but for the sake of learning, we’ll install it ourselves. You tell MongoDB to store that object.ĭata is stored in a format similar to JSON, but enhanced to allow storing more than just basic data types. In MongoDB you can store any object without having to worry about the particular fields that compose this object and how to store them. It’s schemaless, which means you don’t need to pre-define a structure for the data before storing it. It exposes a JavaScript API we can use to create databases and collections of objects (called documents). MongoDB is a very JavaScript-friendly database. Under the NoSQL umbrella we put all those databases that do not use the SQL language for querying the data. Here is an example of how this should look like: db. And in those parentheses, you pass in an object with whatever you want. Now in order to insert a row, just type in the db followed by the name of the collection that you want to insert the row in, and then by insert, which is then followed by parentheses ().
To create a collection in the DB that you are using, you just have to run the following command and set the name of your collection: db.createCollection( 'collection_name')Īnd if you want to view the collection, just run the show command followed by collections and that should print out the collections in your DB. In order to drop a database, or in other words, delete it, you first need to switch to the database with the use command, and after that, you need to type in the following command: db. If you run show dbs after creating a DB, the new DB won't show because it doesn't have anything in it, so don't worry when it doesn't show up after running the show dbs. If you want to create a DB, just type in the use command again, followed by your new DBs name. If you want to switch which database you are using, just type in use followed by the database name. In order to see all of the databases just run the following command: show dbs The command for seeing the current database is: db Now that we have Mongo installed and ready, let's start with some of the main commands that you should know Commands Show Current Database This is what you should see after running the command:Ĭheckout our latest product - the ultimate tailwindcss page creator ? Then run: brew install mongodb-community after that, we will want to run it as a service with the following command: brew services start mongodb-community finally, we need to run the following command so that we can connect and start using MongoDB. Once you get Homebrew installed on your Mac, just run the three following commands.
If you don't have Homebrew installed, just run the code below in your terminal and that will install Homebrew.
We are going to install MongoDB through Homebrew.
This doesn't mean it's better than relational databases, it all depends on how you need to use your database. Unlike a relational database like MySQL, where you have to create all your tables and all your columns, Mongo gives you the freedom to structure your data however we want through our application. Because the data structure is like a JavaScript object, you don't have to map out your entire data structure beforehand as you do with relational databases. It's performant, it's fast, and mostly, it's very flexible. It has built-in replication and sharding. So if you are familiar with JavaScript, then you are going to like Mongo, because it will be easier to get the hang of it. These documents are very similar to JavaScript objects or JSON objects. In NoSQL databases, we store our data in a collection of documents. MongoDB is a NoSQL (not only SQL) database. #database #developer #mongodb #mongo Introduction