Sunday, May 28, 2017

mongoDB

mongoDB Tutorial



MongoDB works on concept of collection and document.

Database
  • Database is a physical container for collections
  • Every database has its own set of files on the system.
Collection
  • Collection is a group of MongoDB documents.
Document
  • A document is a set of key-value pairs.

Database Commands of mongoDB
  • The use Command
    • Used to create database
    • The command will create a new database if it doesn't exist, otherwise it will return the existing database
      • use DATABASE_NAME
  • db Command
    • Used To check your currently selected database
      • db
  • show dbs Command
    • Used  to check your databases list
      • show dbs
  • The dropDatabase() Command
    • This will delete the selected database
      • dropDatabase()
    • If you have not selected any database, then it will delete full database
    • To drop a collection from the database
      • db.collection.drop()
  • The createCollection() Command
    • Used to create collection.
      • db.createCollection(name, options)
        • Name - String
        • Option - Document
  • The insert() Command
    • Used to insert data into MongoDB collection
      • db.Collection_name.insert()
  • The find() Command
    • Used to find data from MongoDB collection
      • db.Collection_name.find()
      • It will display all the documents in a non-structured way
      • To display the results in a formatted way, you can use method.pretty()
        •  db.Collection_name.find().pretty()
      • To find something specific
        • db.mycol.find({},{"title":1,_id:0}) 
  • Less Than, Grater Than Commands

  • And Operation
  • Or Operation

  • And & Or Operation

  • The update() Command
    • Used to update the values in the existing document
      • db.CollectionName.update(SELECTION_CRITERIA, UPDATED_DATA)
      • By default, MongoDB will update only a single document. To update multiple documents, you need to set a parameter 'multi' to true
      • db.mycol.update({'title':'MongoDB Overview'}, {$set:{'title':'New MongoDB Tutorial'}},{multi:true})
  • The save() Command
    • It replaces the existing document with the new document passed in the save() method
      • db.Collectionname.save({_id:ObjectId(),NEW_DATA})
  • The remove() Command
    • Used to remove a document from the collection.
      • db.CollectionName.remove(DELLETION_CRITTERIA)
      • If there are multiple records and you want to delete only the first record, then set justone parameter in remove() method.
  • The aggregate() Command
    • Aggregations operations process data records and return computed results
    • Aggregation operations group values from multiple documents together, and can perform a variety of operations on the grouped data to return a single result
    • For the aggregation in MongoDB, you should use method aggregate()
    • Eg s for Aggregate Functions
      • $sum
      • $ave
      • $min
      • $max
      • $sort
      • $skip
      • $group
    • For More Inoformation -   MongoDB - Aggregation

To Know About MongoDB Commands, Visit www.tutorialspoint.com/mongodb




2 comments:

My First Day with Uki DN Cohort 1

 "Hello WORLD!"