4.MongoDB command Line

Source: Internet
Author: User
Tags tojson

4.MongoDB command Line

①mongodb Command-line Introduction

The MONGO command line is the JavaScript interface for the MONGODB database. This command line can be used to make database pruning, performance management and other operations.

The MONGO command line is a component of MongoDB. When you start MongoDB, you can use the command line to connect to MongoDB.

② Start MongoDB command line

Before starting the MongoDB command line, you need to make sure that MongoDB is started.

Enter MongoDB installation bin directory.

    • Windows

      Performmongo.exe

    • Linux

      ./mongo

MongoDB Default IP and port

MongoDB Default binding IP is 127.0.0.1, Port is 27017. If the MONGO default configuration is not modified. The Execute MONGO command will connect 127.0.0.1:27017.

③mongo Show All databases

Show DBS;

④mongo using or creating a database

If the specified database does not exist, a database is created.

Use dashdan_com

⑤mongo Displays the currently used database

Db

⑥mongo Inserting data

Use Dashdan_comdb.myCollection.insertOne ({x:1});

Description

    • DB is the index of the database currently in use, so don't write the database name here. db

    • The name of the mycollection dataset. This can be customized.

⑦mongo Finding data

Db.myCollection.find ();
If the name of the dataset has spaces or special characters can be obtained by db.getcollection ().

Cases:

Db.getcollection ("mycollection"). Find ();

The MONGO command line receives a maximum of 4,095 characters per line, and the MONGO command shortens it by exceeding this limit.

⑧mongo command output result formatting

Db.myCollection.find (). Pretty ()

You can also set the MONGO command to display the results in the following ways:

    • Print () Prints data and does not format

    • Print (Tojson (

      )) output JSON format, same as Printjson ()
    • Printjson () Output JSON format, with print (Tojson (

      ))

⑨mongo command Multi-line mode

On the MONGO command line, if the{,[,(End, the next line is...Start until you meet the symbol that corresponds to it},],).

> if (x > 0) {... count++; .... print (x); ...}

You can also end this statement by entering two blank lines in a row.

> if (x > 0......>

⑩mongo Command Line exit

Input quit() , or press Ctrl-C .

Reference articles

Official articles

The latest content will be updated at the source station. Reprint please keep the original link: http://dashidan.com/article/mongodb/index.html


This article is from the "13402341" blog, please be sure to keep this source http://13412341.blog.51cto.com/13402341/1976405

4.MongoDB command Line

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.