First understanding of MongoDB

First understanding of MongoDB



0. write in front

  • Linux version: CentOS7.5

  • MongoDB version: MongoDB-5.0.2 (installed in Linux environment)

1. What is MongoDB?

  • MongoDB is written in C++the language and is an 分布式文件存储open source database system based on

  • MongoDB aims to provide scalable high-performance data storage solutions for WEB applications.

  • MongoDB stores data as a 文档data structure consisting of 键值(key=>value) pairs.

  • MongoDB documents are similar to JSONobjects . Field values ​​can contain other documents, arrays and arrays of documents.

As shown below:

[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-I45MwF65-1675912006899)(./1.jpg)]

2. Advantages and disadvantages of MongoDB

advantage:

  • MongoDB is a document storage-oriented database, which is relatively simple and easy to operate;

  • Built-in GridFS, supporting large-capacity storage;

  • Indexes can be set on any attribute in a MongoDB record;

  • MongoDB supports various programming languages: RUBY, PYTHON, JAVA, C++, PHP, C# and other languages;

  • easy installation;

  • Replication (replication sets) and support for automatic failure recovery;

  • MapReduce supports complex aggregations.

shortcoming:

  • does not support transactions;

  • take up too much space;

  • Table association cannot be performed;

  • Complex aggregation operations are created through MapReduce, which is slow;

  • MongoDB does not reclaim space on the file system after you delete a record. Unless you delete the database.

3. Analysis of basic concepts

SQL terms/concepts MongoDB terms/concepts explain
database database database
table collection Database Table/Collection
row document Data record line/document
column field data fields/fields
index index index
table joins not support Table join, MongoDB does not support
primary key primary key Primary key, MongoDB automatically sets the _id field as the primary key

Through the example in the figure below, we can also understand some concepts in Mongo more intuitively:

[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-rdsewoM6-1675912006900)(2.jpg)]

4. Installation

4.1 Download address

https://www.mongodb.com/download-center#community

4.2 Install MongoDB

I installed it on the node02 machine

  • Upload the downloaded compressed package to the virtual machine, then decompress and install
[whybigdata@node02 software]$ tar -zxvf mongodb-linux-x86_64-rhel70-5.0.2.tgz -C /opt/module/        
  • double naming
[whybigdata@node02 module]$ mv mongodb-linux-x86_64- rhel70-5.0.2/ mongodb 
  • Create database directory

The data of MongoDB is stored in the db directory of the data directory, but this directory will not be created automatically during the installation process, so you need to manually create the data directory and create the db directory in the data directory.

[whybigdata@node02 module]$ sudo mkdir -p /data/db 
[whybigdata@node02 mongodb]$ sudo chmod 777 -R /data/db/   
  • Start the MongoDB service
[whybigdata@node02 mongodb]$ bin/mongod
  • View mongod process
ps -ef | grep mongod | grep -v grep | awk '{print$2}'

The above process query command is equivalent to the following command

pgrep –f mongo

4.3 pgrep use

  • How to use
[whybigdata@node02 mongodb-5.0.2]$ pgrep --help

Usage:
 pgrep [options] <pattern>

Options:
 -d, --delimiter <string>  specify output delimiter
 -l, --list-name           list PID and process name
 -a, --list-full           list PID and full command line
 -v, --inverse             negates the matching
 -w, --lightweight         list all TID
 -c, --count               count of matching processes
 -f, --full                use full process name to match
 -g, --pgroup <PGID,...>   match listed process group IDs
 -G, --group <GID,...>     match real group IDs
 -n, --newest              select most recently started
 -o, --oldest              select least recently started
 -P, --parent <PPID,...>   match only child processes of the given parent
 -s, --session <SID,...>   match session IDs
 -t, --terminal <tty,...>  match by controlling terminal
 -u, --euid <ID,...>       match by effective IDs
 -U, --uid <ID,...>        match by real IDs
 -x, --exact               match exactly with the command name
 -F, --pidfile <file>      read PIDs from file
 -L, --logpidfile          fail if PID file is not locked
 --ns <PID>                match the processes that belong to the same
                           namespace as <pid>
 --nslist <ns,...>         list which namespaces will be considered for
                           the --ns option.
                           Available namespaces: ipc, mnt, net, pid, user, uts

 -h, --help     display this help and exit
 -V, --version  output version information and exit

For more details see pgrep(1).

4.4 Enter the shell interaction page

[whybigdata@node02 mongodb]$ bin/mongo

Linux installation MongoDB can refer to this article:

https://juejin.cn/post/7147226612978122760

Finish!

Guess you like

Origin blog.csdn.net/m0_52735414/article/details/128949474