MongoDB Configuration and basic usage

Source: Internet
Author: User

MongoDB Installation

Official website: https://www.mongodb.com/

Brochure: https://docs.mongodb.org/manual/

Win7 system needs to install patches, KB2731284

    • Setup finishes configuring environment variables:
    • C:\Program Files\mongodb\server\3.0\bin added to the system's PATH environment variable
Basic commands
    • Gongod: Boot
    • Mongoimport Importing Data
    • MONGO use the database, the environment after running this command is MONGO syntax.
    • Show DBS: List all databases
    • Use database name: using a database
    • DB: View your current database

Note: If you use a database that does not exist, it is new, but only after you execute the INSERT Data statement can you create a new success.

Use of the database

To manage the database, you must turn on the boot, use the mongod--dbpath c:\mongom Command (--dbpath is the folder where the database document is selected)

1. Inserting data
    • Normal insertion

      db.student.insert({"name":"xiaoming"});

    • Import data

      /**/--db test--collection restaurants--drop--file Primer-dataset.json
2. Querying data
    • Search All

      db.restaurants.find()

    • Exact match

      db.student.find({"score.shuxue":80});

    • Multiple conditions

      db.student.find({"score.shuxue":80 , "age":22})

    • Greater than condition

      db.student.find({"score.yuwen":{$gt:60}});

    • Or

      db.student.find({$or:[{"age":18},{"age":22}]});

    • Sort

      db.restaurants.find().sort( { "borough": 1, "address.zipcode": 1 } )

3. Modify the data
    • Single Data modification

      db.student.update({"name":"小明"},{$set:{"age":22}});

    • Change multiple matching data (plus multi parameter)

      db.student.update({"score.shuxue":80},{$set:{"age":26}},{multi: true});

    • Complete replacement (without $set keyword)

      db.student.update({"name":"小明"},{"name":"大明","age":28});

4. Delete data
    • db.restaurants.remove( { "borough": "Manhattan" } )

MongoDB Configuration and basic usage

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.