Upgrade to Pro — share decks privately, control downloads, hide ads and more …

MongoDB important commands

MongoDB important commands

With this slide, What is MongoDB and some brief information and also you know some basic commands like connection,stop the connection,help and other CRUD operation in briefly

Avatar for nuthanmurari

nuthanmurari

February 06, 2015

Other Decks in Technology

Transcript

  1. MongoDB Overview 1. MongoDB name came from (humong ous). 2.

    MongoDB is an Open-Source document database. 3. MongoDB provides high performance. 4. MongoDB provides high availability. 5. MongoDB provides Easy scalability. 6. MongoDB works in all platforms (i.e., Cross-Platforms).
  2. Key Features 1. Indexing: Index is conceptually similar to RDBMS.

    In MongoDB, Secondary index is also available. Any Field in MongoDB can be indexed. 2. Replication: In MongoDB, Replications achieves using replica set. A Replica Set consists of one or more copies of data. Here two roles of replica set. 2.1: Primary 2.2: Secondary Primary replica contains both read and write by default but secondary having only read permissions on data. In Secondary, Having copies of primary data. If primary fails then secondary should be as primary.
  3. Overview on Environment Usage In Windows In order to work

    with MongoDB, we need environment (i.e., mongo) shell. In this we are using JavaScript language to work with mongo shell. And I listed some needed commands to start MongoDB Commands: In order to connect to MongoDB using mongo shell 1. mongo – Connect to MongoDB 2. db – To know the current database. After installation by default test database is used. 3. show dbs – List all available databases 4. use newdb – where newdb is database name. Switch to new database. 5. help – Provide help to work in shell There are different names we are using in MongoDB compare to SQL and I listed some keyword below, all the keywords will see in coming chapters. Note: Some main naming changes over SQl vs NoSQL database languages 1. database - database 2. table – collection 3. rows – documents 4. columns – fields For glance, I am showing some simple and basic operations in MongoDB. Will see in detail in coming chapters.
  4. Collection Creation & Insert the documents In MongoDB, there is

    a power full feature (i.e., dynamic schema) Means if there is no collection in database, dynamically created and there is no structure before inserting a document Ex. Of entered some data The below commands are used to insert the above documents in test collection. And also added some new collections which are not already in database, even those are created With the help of below command, we see all collections which are recently created Command: show collections In order to check whether document is inserted in the collection or not, for this we use the below command
  5. Command: db.test.find(); Ex: Where ObjectId is unique to each field,

    no need to insert any value to _id field Insert records using for loop To see the records, use the following command but it returns by default only 20 documents, if see other documents then type “it” in command prompt
  6. If you want to find particular field with value then

    use the following command, Command: db.testnuthan.find( {x:9})
  7. Cursor vs document Cursor comes if having more than 20

    documents Ex for cursor: Document comes only one or less than 20 Ex for document
  8. If you want to get only one document, use the

    below one, By default , it list only 20 documents and then type “it“ will get other 20 ,…. Even result set contain 100 documents or more. Even we can set limit to improve perfomance, use the following method Synatax : limit(number of documents) Command : db.testnuthan.find().limit(3) – return 3 documents