INTRO:-
MongoDB is an open-source document database and leading NoSQL database.
Paste Article Duplication Processing Re-Write Suggestion Done (Unique Article)
1. to make a data
Use the command — use data name>
2. To list the Databases within the Mongolian monetary unit dB system.
Use the command — show dbs
This command can show the default DB’s and also the one’s created by the consumer. but If there aren't any collections within the dB created then it won’t be shown within the list. conjointly to ascertain that data is presently elect then use the command- dB. The below image shows the data that
currently being operated on.
3. Drop data
Use the command — dB.dropDatabase(). Follow the below commands wherever the databases ar shown before and once dropping the chosen data. we have a tendency to cannot specify a particular data name. The data that is presently elect are mechanically deleted. conjointly we've got inserted some knowledge into sampledb that is why it's showing within the list. If no knowledge was there in sampledb then wouldn't have appeared once writing the command — show dbs.
4. produce assortment
The below method shows show to make a set in an exceedingly data. within the assortment lies the document. Use the command — dB.collectionname.insert(). The below image shows just one document created within the assortment ‘Country’. we are able to produce multiple documents within the same assortment. This assortment refers to the Table for HBase or either a relation DBMS.
The below example shows a set having multiple documents. Notice the quantity of fields in each the documents. the first document doesn't have the suburban area field which implies we've got to insert solely those data that is obtainable with United States of America.
5. to search out the documents within the assortment
Use the command- dB.collectionname.find(). the item ID’s would be appended to the every document on it’s own. this may build every document distinctive.
We can conjointly use AND and OR operator to search out specific documents at intervals the gathering. for example to search out the document that has the town city use the below command:
db.country.find();
6. Update the Document at intervals the gathering
To update a selected field use the command-
db.collectionname.update(,})
Before Update
After Update
7. Delete a Document
To delete a document use the below command-
db.collectioname.remove()
We can conjointly use the command dB.collectionname.remove() to truncate the whole assortment and has been supplemental within the Version two.6. Earlier the command dB.collectionname.remove() accustomed work. this is often resembling the truncate command in SQL.
8. Projection of rows
To select the desired fields we are able to use the below given command. we want to append either ‘1’ or ‘0’ to the sector within the command. If we have a tendency to provides a ‘1’ then all the rows for that field can seem and ‘0’ can provide the other way around results. If the sector name isn't laid out in the command then it default takes a ‘1’ for the item ID field, this case doesn't applied for all the opposite field s within the list. The fields here correspond to the columns in RDBMS.
db.collectionname.find(,field:1})
9. Limiting the rows
This is the advanced version of projected the rows. In Projection technique all the rows would seem leading to United States of America obtaining unwanted knowledge. Here we are able to limit the columns additionally as skip few of the rows. Use the command -db.collectionname.find(,zero,field:1 or 0…}).limit(1).skip(1). This methodology can retrieve just one row. the quantity of skips determines the quantity of rows which will be aloof from the result.
10. Sorting the rows
In this methodology we are able to type the rows within the ascending or downward-sloping manner. choose the fields that ar required so append a one or -1 to the type command. Default is one, thence in such a case the type command needn't be specific. The ascending or downward-sloping are supported the column elect within the type command.
Command: dB.country.find(,).sort()
These ar the few ways to control with Mongolian monetary unit dB. The syntax ar user friendly and easy to know. Associate in Nursing another advantage of this data is, we want not embody all the fields all told the documents at intervals an equivalent assortment. for example, If one document contains a field named town and also the alternative document doesn't would like it then we want not embody it. This helps in saving plenty of area. talk to the below example














No comments:
Post a Comment