Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

4.MongoDB Command Line

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

4.MongoDB Command Line

The latest content will be updated at the origin server. To reprint, please keep the original link: http://dashidan.com/article/mongodb/index.html

Introduction to the ① MongoDB Command Line

The mongo command line is the JavaScript interface of MongoDB database. You can use this command line to add, delete, modify and query the database, performance management and other operations.

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

② starts the MongoDB command line

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

Enter the bin directory in the installation of MongoDB.

Windows

Execute mongo.exe

Linux

. / mongo

MongoDB default IP and Port

The default binding IP for MongoDB is 127.0.0.1 and the port is 27017. If the default configuration of mongo is not modified. Executing the mongo command will connect 127.0.0.1 to 27017.

③ mongo displays all databases

Show dbs

④ mongo uses or creates a database

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

Use dashdan_com

⑤ mongo shows the current database usage

Db

⑥ mongo insert data

Use dashdan_comdb.myCollection.insertOne ({x: 1})

Description:

Db is the index of the database currently used. Do not write the name of the database here. Is to adopt db.

Name of the myCollection dataset. This can be customized.

⑦ mongo find data

Db.myCollection.find (); if there are spaces or special characters in the name of the dataset, you can get it by db.getCollection ().

Example:

Db.getCollection (myCollection) .find ()

The mongo command line receives a maximum of 4095 characters per line, and the mongo command shortens it beyond 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 without formatting

Print (tojson (

) output in JSON format, same as printjson ()

Printjson () output in JSON format, the same as print (tojson (

))

⑨ mongo command multiline mode

If you end with {, [, () on the mongo command line, the next line will begin with. At the beginning, until the corresponding symbol},],) is encountered.

> if (x > 0) {... Count++;... Print (x);...}

You can also type two blank lines in a row to end the statement.

> if (x > 0. >

⑩ mongo Command Line exit

Enter quit (), or press Ctrl-C.

Reference article

Official website article

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report