Learning MongoDB #0 : Intro

2년 전

What Will I Learn?

  • You will learn basic understanding about what is database and how it's works
  • You will learn how to install and run a MongoDB on Windows 10
  • You will learn all the fundamentals of MongoDB

Requirements

  • A working computer running on Windows
  • The ambition to learn MongoDB

Difficulty

  • Basic / Intermediate

Why I start this series?

Because there was a few old tutorial about NoSQL or MongoDB but most of them not enough. There wasn't a fully completed series about this (I saw @superoo7 and @morningtundra’s some posts.) Mostly just one shots. So, I want to start this series.

What is database?

I think we need to start with data before database. What is data? All requests, steps, processes, works of creating and managing by companies/websites/apps or a person are a data. If you are writing with your girlfriend via any app, you are creating data about it. Or if you sell or buy anything on online or a moll you'll create a data. In modern world, your all step is a data. But you don't see this giant data pool, even don't notice it. Because ever data are processing on database. Because database is a kind of notebook for saving, managing, filtering, sorting datasets. Like a phonebook. You can access a data on database after right steps. We use it mostly My SQL, Oracle etc. We can record and manage a data via this services. Also we are using a worldwide standard, SQL -Structured Query Language- query language. But in this tutorial series we'll use NoSQL -Not only SQL- language with MongoDB.

What is NoSQL?

NoSQL is a non-relational database management system used to organize big data in distributed situations. Much personal data is produced, especially in social media and forums. They may be distributed and intertwined. Like the comment coming to the comment and the comment coming to it. NoSQL is one of the best option for this kind growing data pools. Because we can't storage or manage this much data with SQL. In NoSQL systems, it doesn't matter another data is affected or not when we update or delete a data. Because data sets aren't stored in an associated or interconnected manner. So, we don't need to check other data when we need to delete or change a data. This skill make NoSQL faster. But this skill also create some security holes on database too.


Image source | CAP Theorem

In 1998 Eric Brewer had a theory about it, CAP Theory or a.ka. Brewer Theory. Brewer said, in a distributed architecture we should pay attention to three headings.

  • Consistenty : A distributed database must be consistent. This mean, every single client must be accessible with their updated version. All clients must have same view of the data.
  • Availability : A database always sould be ready to use, write or read. Some servers can be broke but it shouldn't be a problem. Each client can always read and write.
  • Partition Toleramce : Every distributed systems can always storage on database even they had connecting problem each other. The system works well despite physical network partitions.

These three basic features are very important for a distributed database system. The system must have there of them.

Introducing MongoDB

MongoDB is an open source document oriented NoSQL database app which developed via C++. MongoDB storage data on BSON (Binary JSON) type in blocks called by Document. This feature help data read/write speed, to make it faster. Also with help of this feature we can query a data like using OOB. Let's see a simple example for BSON type data.

{
      id : 1,
      user: "vigna",
      job: "content writer"
}

How to install and run MongoDB on Windows?

So, let's install MongoDB and start to code!

  • MongoDB Download Link. You can download on this link (it's official site). Also there is a big guidance for downloading if you need : Install MongoDB.
  • After install and set up MongoDB, you need to create a database file for run mongod.exe and start to work. Open C:\Program Files\MongoDB\Server\3.6\bin path and create a short cut on your desktop for mongo.exe and mongod.exe . After did it, you should create an empty file for database on C:\ which have a path like \data\db. So, this is our database storage and we are ready to say "Hello" to world!
  • Now, you can run mongod.exe and see how it lissen port 27017 as a server.

How can create my first database?

When you run mongo.exe app you will see Mongo Shell. Mongo Shell is a java script based client tool for manage your data on MongoDB. When you write help on the terminalyou can learn which commands you can use.

As you see we should use use keyword for create a database. Let's try it.

Our thamplate is use [db_name]. When we do that, we create a database named by db_name. So, let's add a collection and a variable. But what is collection? When you first store data in the database, such as by creating a collection, MongoDB creates the database.

In this example, database term is equal usual database term. The place which data was store. Also we can say it collection is equeal database schema in MongoDB. Collections store document records. So, in our example db refers to the current database and vignaCollection is the name of the collection. If you want to see collection list just write show collections on client terminal. But document represent physical data which will add on table. Let's see an example about documents:

And learn some operations definitions:

operationsDescription
db.collection.find()Find all documents in the collection and returns a cursor.
db.collection.insertOne()Insert a new document into the collection.
db.collection.insertMany()Insert multiple new documents into the collection.
db.collection.updateOne()Update a single existing document in the collection.
db.collection.updateMany()Update multiple existing documents in the collection.
db.collection.save()Insert either a new document or update an existing document in the collection.
db.collection.deleteOne()Delete a single document from the collection.
db.collection.deleteMany()Delete documents from the collection.
db.collection.drop()Drops or removes completely the collection.
db.collection.createIndex()Create a new index on the collection if the index does not exist; otherwise, the operation has no effect.
db.getSiblingDB()Return a reference to another database using this same connection without explicitly switching the current database. This allows for cross database queries.

A little example for collection and document :

 db.users.insert({ 
    name: "vigna",
    company: "utopian" ,
    planet: "world",
    contents: ["blockchain", "mongoDB", "meme"],
    posts: 20
 })

So, this is the intro of series. I don't want to push here lots of code exam, just wanna introduce MongoDB, NoSQL, bigdata and database term.



Posted on Utopian.io - Rewarding Open Source Contributors

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
STEEMKR.COM IS SPONSORED BY
ADVERTISEMENT
Sort Order:  trending

Thanks for the contribution.


Need help? Write a ticket on https://support.utopian.io.
Chat with us on Discord.

[utopian-moderator]

That's a very good explanation of NoSql . I look forward to reading your series @vigna.

·

Thanks :))

·
·

Your welcome @vigna..😊😊

Good one 😁👍

Hey ! THANKS FOR THE EXPLAINATION . Are you planning on launching a video tutorial on this ? IK HTML, CSS ,LITTLE BIT OF JAVASCRIPT , LOOKING FORWARD TO LEARN QUERY LANGUAGE .

·

No, video tutorial isn't my style. But I will write more :)

·
·

Okay cool. KEEP UP THE GOOD WORK !

Hey @vigna! Thank you for the great work you've done!

We're already looking forward to your next contribution!

Fully Decentralized Rewards

We hope you will take the time to share your expertise and knowledge by rating contributions made by others on Utopian.io to help us reward the best contributions together.

Utopian Witness!

Vote for Utopian Witness! We are made of developers, system administrators, entrepreneurs, artists, content creators, thinkers. We embrace every nationality, mindset and belief.

Want to chat? Join us on Discord https://discord.me/utopian-io