MongoDB command line basic syntax

Source: Internet
Author: User

The first is to install and configure MongoDB, this please self-Baidu, after the installation is complete, open the cmd command input MONGO. Let's start with an example, let's say that there is a class called C1, there are several people inside, people have names, age, gender and class, we operate on them separately.

  the first step to viewing your database

Show DBS

  The second step is to create a database    

Use Ceshi

  The third step is inserting data into the database  

Db.test.insert ({"_id": "0", "name": "Xiaozhang", "age": +, "class": "C1", "Sex": "Woman"})

Db.test.insert ({_id: "1", Name: "Xiaoming", Age:15,class: "C1", Sex: ' Man '})

Db.test.insert ({_id: "2", Name: "Xiaowang", Age:17,class: "C1", Sex: ' Man '})

Db.test.insert ({_id: "3", Name: "Shanchu", Age:42,class: "C1", Sex: ' Man '})

Create a new test table in the testing database and insert the data note that the new database is not being inserted into the new database.

  The fourth step updates the current test data table

    Db.test.update ()

  The fifth step shows the data table of the current data test

  Show collections

  Sixth step to see all the data in the table
Db.test.find ()

  Seventh step change the age of the first piece of data

    Db.test.save ({"_id": "0", "name": "Xiaozhang", Age:18,class: "C1", Sex: "Man"})

If the change succeeds there will be Writeresult ({"nmatched": 1, "nupserted": 0, "nmodified": 1}) Note:the "_id" inside the save is to be matched, if not specified, a new data insert is generated. To the data table, in fact, this method is to delete the data after the new insert, if you just want to change the field name of a property, then you need to write these other properties are complete, otherwise there will only be a field name is inserted, the other field names are all deleted!!!

At this point you can use Db.test.find () to view the current data

  Eighth Step Delete fourth data

    Db.test.remove ({"Name": "Shanchu"}) uses Db.test.find () to view the current data

  Nineth step to find matching items

Db.test.find ({"Age": {$gt: +}}) "$lt", "$lte", "$gt", "$gte" correspond to <,<=,>,>=

At this point, you can see data that's older than 17.

  Step Tenth Delete the entire data sheet

    Db.test.drop () Use show collections to see if the test table exists

  Step 11th Delete the database 

First use test to create a table and insert a piece of data, you can refer to the above method, using Db.dropdatabase () delete the current database, delete after the library using show DBS to see if the database was deleted successfully

To this MongoDB some basic syntax has been introduced, more content please look forward to the next update.

  

  

  

  

MongoDB command line basic syntax

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.