当前位置:网站首页>Explore mongodb - mongodb compass installation, configuration and usage introduction | mongodb GUI

Explore mongodb - mongodb compass installation, configuration and usage introduction | mongodb GUI

2022-07-04 15:45:00 The way of several people

The way of several original articles , Please contact us for reprint

MongoDB Compass yes MongoDB Developed and provided by the official website MongoDB GUI( Graphical user interface ) Management tools . It can explore data visually 、 Run instant queries in seconds 、 Create databases and manage collections and documents 、 And data exchange CRUD function 、 View and optimize query performance 、 Build geographic query, etc . So that you can index 、 Make more reasonable decisions in terms of document verification . Provide Linux、Mac And Windows edition .

1

Compass Introduce

The following is the official website of MongoDB Compass Introduction to .

1.1

Use built-in schema visualization to understand data

MongoDB Compass Analyze your documents , And through intuitive GUI Show the rich structure within your collection . It allows you to quickly show and explore your patterns , To understand the frequency of data sets 、 Category and field range .

1.2

Instantly understand server status and query performance

Real time server statistics allow you to view key server metrics and database operations . Easily analyze database operations in depth , Know your most active collection .

1.3

Visually view geospatial data 、 Understanding and operation

Click to build a complex query , Then execute the query with one click ,Compass The results will be displayed for you by geographical location , The results will also be displayed as groups JSON file .

1.4

Better CRUD Operation mode makes data interaction easier

Use an intuitive visual editor to modify existing documents more confidently , Or click a few times to complete the insertion 、 Copy or delete documents

1.5

Use visual interpretation plans to understand performance issues

Through easy to understand GUI Understand the operation of the query , Identify and resolve performance issues .

1.6

View utilization and manage indexes

Know the type of your index 、 size 、 Utilization and special properties . One click to add and remove indexes .

1.7

Simpler data verification

Write in the smart editor JSON Schema validation rules , It automatically suggests field names 、BSON Data types and validation keywords . Real time preview of documents that pass and fail validation rules , It is easy to see whether the rule has the expected behavior .

1.8

Through plug-in extension

Compass Plug in framework with API Open form , Users can extend it . Want other functions ? You can install plug-ins or build your own .

1.9

Aggregation becomes easy

In the intuitive UI Build an aggregation pipeline . The code skeleton and auto fill function facilitate the easy construction phase , The document preview can show whether the operation you need is being performed at this stage . Add and remove phases , Or reorder in the pipeline by dragging and dropping . After completion , Export to native code for use in your application .

2

Compass install

Go to... Through the following address MongoDB Download on Compass, And install :

https://www.mongodb.com/try/download/compass

At present Windows、Mac、RedHat、Ubuntu The version of is available for download . Here to download Windows Version to install .

download msi Format of the installation file , It can be installed directly .

3

Compass To configure

Use MongoDB Compass front , Need configuration Compass Connection information , To connect MongoDB Access to the database server .

3.1

Prepare before configuration

Conduct MongoDB Compass Before configuration , You need to check the server first mongod.conf And sshd_config Profile modification .

3.1.1. modify mongod.conf The configuration file

In the installation MongoDB Edit on the server mongod.conf The configuration file (MongoDB Please check the installation introduction of 《 First time to know MongoDB - MongoDB Introduction and installation 》):

sudo vim /etc/mongod.conf

take net.bindIp Parameters from 127.0.0.1( Only local connections are allowed by default ), It is amended as follows 0.0.0.0 ( Allow all IP Address connection ):

chart 3-1-1: modify mongod.conf The configuration file

3.1.2. modify sshd_config The configuration file

In the installation MongoDB Edit on the server sshd_config The configuration file :

sudo vim /etc/ssh/sshd_config

Add a line at the end of the file , Allow it to pass TCP Connect :

AllowTcpForwarding yes

chart 3-1-2: modify sshd_config The configuration file

3.1.3. restart ssh

Restart with the following command ssh:

sudo service sshd restart

3.1.4. restart MongoDB service

Restart with the following command MongoDB service :

sudo systemctl daemon-reload

Check the service status after restart .

3.2

To configure Compass

open MongoDB Compass Applications , Get into Compass After that, the connection interface appears first, as follows ( Connection string mode ):

chart 3-2-1:MongoDB Compass Initial interface

The format of the connection information string is :

mongodb://[username:[email protected]]host1[:port1][,...hostN[:portN]][/[defaultauthdb][?options]]

With the author's stand-alone (Standalone) Take the installation mode as an example , The connection address information is ( The default port number is 27017):

mongodb://hadoop100:27017/?readPreference=primary&appname=MongoDB%20Compass&ssl=false

You can also switch to the connection information configuration mode and input the connection information :

chart 3-2-2:MongoDB Compass Connection information configuration

After setting up , Click on Connect, You can connect to MongoDB:

chart 3-2-3: see MongoDB database

You can see the installation MongoDB By default, the three databases initially created , The left side shows Database list , The right side is Database The storage size of 、Collections Quantity and Indexes Quantity information .

4

Compass Use

Here are some examples of common operations , Learn how to use MongoDB Compass.

4.1

Create and delete databases

Click on CREATE DATABASE Button , You can create a database , At the same time, a set must be created :

chart 4-1-1:Compass Create database

Click the trash can button , And enter the database name , You can delete the database :

chart 4-1-2:Compass Delete database

The operation is very convenient .

4.2

Add and delete collections ( object )

Click the database name to enter the database , Click on CREATE COLLECTION Button , You can add a set ( object ):

chart 4-2-1:Compass New set

Click the trash can button , And enter the set name , You can delete the set :

chart 4-2-2:Compass Delete the collection

Capped Collection For a fixed set , That is, for a fixed size , We can imagine it's like a circular queue , When the assembly space is used up , Then the inserted element will cover the original head element .

4.3

Insert 、 Update and delete documents

Click the set name to enter the set , You can view all document data stored under this collection . There are three ways to view document data :list、bson、table.

chart 4-3-1:Compass list Display document data in form

chart 4-3-2:Compass bson Display document data in form

chart 4-3-3:Compass table Display document data in form

4.3.1. Inserted into the document

There are two ways to insert document data : Import from file 、 Enter document data manually .

Click on ADD DATA Under the button Import File, By importing JSON or CSV Insert document data by file :

chart 4-3-4:Compass Insert document data by importing files

Data file source :《 How to quickly obtain and analyze the housing price market in your city ?

Click on ADD DATA Under the button Insert Document, Insert the document by manual input :

chart 4-3-5:Compass Insert document data by manual input

4.3.2. Update the document

Click the Edit button of each document data record , The document data record can be updated , Including modifying data types 、 Add and delete document elements 、 Modify the key name and value content of the document element :

chart 4-3-6:Compass Update document data type

chart 4-3-7:Compass Update document data

4.3.3. Delete the document

Click the Edit button of each document data record , You can delete the document data record :

chart 4-3-8:Compass Delete document data

MongoDB Compass stay CRUD The operation of is very humanized , However, it is not suitable for mass operation .

4.4

Query the document

Documented FILTER Enter the query criteria in the row , Click on FIND Button , You can execute the query operation , You can also export Python、Java And other languages .

for example , The inquiry house type is 3 room 2 hall , The house facing south , stay FILTER Enter the following criteria to query :

{huxing: "3 room 2 hall  ", chaoxiang: "  south  "}

chart 4-4-1:Compass Query the document

You can find 303 Document data records .

export Python、Java And other languages :

chart 4-4-2:Compass Export query statements in other languages

You can see , The exported statement is very complete , Directly available .

4.5

Create index

On the collection page Indexes in , You can view the index of the corresponding set , The index "_id_" Is the unique index specified in the system , Not delete .

chart 4-5-1:Compass View the index of the collection

By clicking on CREATE INDEX Button can create an index . Enter index name , And select the key for indexing 、 Index order , You can also configure the type of index 、 Properties, etc :

chart 4-5-2:Compass Create index

If you check Create unique index, Make sure that the key value of the indexed key has no duplicate value ;Partial filter expression It can be used to set index conditions , That is, the index key will be indexed only if it meets the set conditions , Can be used to constrain non null values , For example, setting the following conditions means that only There are key values positioninfo Index :

{ "positioninfo": { "$exists": true } }

Partial indexes It can reduce the use of storage space , Improve performance .

4.6

View execution plan

stay MongoDB shell There is explain() function , Used to detect the operation of diagnostic data .Explain Plan Its function is similar , Used to view the execution plan of query statements 、 Evaluate query performance , General application in find() Query function 、 Evaluation index, etc .

chart 4-6-1:Compass View the query statement execution plan

You can use tree or native JSON Format view statement execution order 、 Returns the number of results 、 Time consuming 、 Number of scanned records 、 Execution information such as index usage .

4.7

Monitor resource usage

Click on the home page Performance Tab can be monitored MongoDB Use of resources :

chart 4-7-1:Compass Monitor resource usage

You can view the operation commands 、 Reading and writing I/O、 network bandwidth 、 Memory usage 、 Resource monitoring information such as hotspot collection .

4.8

Use Mongo Shell

MongoDB Compass Integrated MongoDB Shell, Click... At the bottom of the interface >_MONGOSH You can enter , With the MongoDB Use... In the server mongosh The usage and effect of , Can be written directly MongoDB Statement for database operation .

chart 4-8-1:Compass Use in Mongo Shell


MongoDB Compass There are other rich functions , You can download and install to use , Experience 、 Explore .

Cover picture : Striped wildebeest migrating on Serengeti grassland in Tanzania

Copyright information : jacobeukman / iStock / Getty Images Plus

原网站

版权声明
本文为[The way of several people]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202141224391994.html