-->

  • mongodb basic command

     

     

    mongodb basic command

     

     

    Mongodb basic command



    This blog and in upcoming blog we will see mongodb basic and how is it work with installation and after installation we should not face any problem while making Database, collection(table) and using the data in nodejs even whenever we will make API.



    • # What is MongoDB
    • # MongoDB vs SQL
    • # MongoDB basic commands


     

    Now in this blog we will consider about mongoDB basic command which we can use to create Database, collection etc.


     

     What is MongoDB

     

    MongoDB is a popular open-source NoSQL (non-relational) database management system. NoSQL means no structure like it is look like an object while in SQL it is a structure query language like SELECT CustomerName, City FROM Customers; (The SELECT statement is used to select data from a database.) But NoSQL database is useless...NOT completely because of whenever we want add extra column in database then it is possible through NoSQL MongoDB.  



    Object Like - 

     

     

    {
      "_id": {
        "$oid": "659ad46e0382148123c82841"
      },
      "name": "moto G60",
      "brand": "motorola",
      "price": 16500,
      "category": "mobile"
    }
    
    
    

     

     

    Set Enviornment and Install MongoDB - CLICK HERE

     


    MongoDB is a type of database that helps store and manage large amounts of data in a flexible and scalable way. Unlike SQL, MongoDB doesn't require a fixed structure for the data, allowing you to store information in a more versatile format.


    • MongoDB is a NoSQL database.
    • The data stored in a collection
    • Collection don't have row and columns
    • Data is stored in the form of object.



     

    MongoDB vs SQL

     

    In SQL - 

    • It is a structured form.
    • There is a row and column form.
    • When we want add extra column after creating table then we face some problem.
    • When an inbox is optional where any user may or not fill in that box, memory may be wasted in that database.

     

     

    mongodb basic command

     

     


    In MongoDB - 

    • It is an unstructured form.
    • There is a collection form.
    • When we want add extra column and rows we can do it easily because it is in object form.
    • Here any user can fill the data as per his choice less or more.

     


     

    mongodb basic command

     

      

     

    MongoDB basic commands

     

    You can use mongodb in GUI or CLI mode but moslty beginner will using GUI (mongodb compass tool). So, we will start from mongodb start and stop command in command prompt windows.


    net start MongoDB 

    net stop MongoDB

     


    mongodb basic command


    After starting mongoDB  server and you can use this URL mongodb://localhost:27017 for connecting nodejs.



    In GUI Mode


    Open MongoDB compass tool and simple click on connect or save or connect button.



    mongodb basic command


     

    And copy the accessing URL.

     

     


    mongodb basic command


    Now click on icon and create a database name and collection name.



    mongodb basic command


    CLI MODE


    Finally we have to start create database name, collection, read, update, delete through command line interface in mongoose terminal.


    Simple click on mongoose button on MongoDB compass tool.



    mongodb basic command


    1. show dbs   (database check)
    2. use youtube  (create db)
    3. db.createCollection('videos')  (create table)
    4. show collections       (check table)
    5. db.videos.drop()  (to delete table)
    6. db.dropDatabase()      (to delete database)
    7. use admin (another db)



    mongodb basic command


    Still database not created because we have not created the table yet, even the name of database is not being shown.If you have used SQL  then you would know that it also does not show a database. Unless you create a table in it.



    mongodb basic command


    For creating table you can use db.createCollection('videos') 

     

     

    mongodb basic command

     

     Just like that you can create collection, show collection, drop the collection and database etc.



     

    mongodb basic command

     

     Insert Data

     

    You can insert data in mongodb by CLI mode through this command db.products.insertOne({name: 'moto G60', brand: 'motorola', price: 1800, category: 'mobile'})

     

     

    mongodb basic command

     

     db.products.insertOne({name: 'moto G60', brand: 'motorola', category: 'mobile', price: {actualAmount: 20000, discount: 2000}})

     

     

    mongodb basic command

     


    mongodb basic command


    UpdateOne


    db.products.updateOne({name: "moto G60"}, {$set: {brand: "oppo"}})


    mongodb basic command



    DeleteOne


    db.products.deleteOne({brand: "moto G60"})



    mongodb basic command




    Disclaimer



    All tutorials are for informational and educational purposes only and have been made using our own routers, servers, websites and other vulnerable free resources. we do not contain any illegal activity. We believe that ethical hacking, information security and cyber security should be familiar subjects to anyone using digital information and computers. Hacking Truth is against misuse of the information and we strongly suggest against it. Please regard the word hacking as ethical hacking or penetration testing every time this word is used. We do not promote, encourage, support or excite any illegal activity or hacking.




  • 0 comments:

    Post a Comment

    For Any Tech Updates, Hacking News, Internet, Computer, Technology and related to IT Field Articles Follow Our Blog.