NoSQL (2)

majaeh43ยท2021๋…„ 12์›” 6์ผ
0

MongoDB Package Components

๐Ÿค MongoDB 3๊ฐœ์˜ Core Process ๐Ÿค

  • mongod: ํ•ต์‹ฌ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ํ”„๋กœ์„ธ์Šค
  • mongos: ์ƒค๋”ฉ๋œ ํด๋Ÿฌ์Šคํ„ฐ์šฉ ์ปจํŠธ๋กค๋Ÿฌ ๋ฐ ์ฟผ๋ฆฌ ๋ผ์šฐํ„ฐ
  • mongosh: interactive shell

1) mongod

mongod is the primary daemon process for the MongoDB system. It handles data requests, manages data access, and performs background management operations.

This document provides a complete overview of all command line options for mongod. These command line options are primarily useful for testing: In common operation, use the configuration file options to control the behavior of your database.

mongod๋Š” MongoDB ์‹œ์Šคํ…œ์˜ ๊ธฐ๋ณธ ๋ฐ๋ชฌ ํ”„๋กœ์„ธ์Šค.
๋ฐ์ดํ„ฐ ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•˜๊ณ  ๋ฐ์ดํ„ฐ ์•ก์„ธ์Šค๋ฅผ ๊ด€๋ฆฌํ•˜๋ฉฐ ๋ฐฑ๊ทธ๋ผ์šด๋“œ ๊ด€๋ฆฌ ์ž‘์—…์„ ์ˆ˜ํ–‰.
config ํŒŒ์ผ์„ ์ด์šฉํ•˜์—ฌ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ ๋™์ž‘์„ ์ œ์–ด.

2) mongos

For a sharded cluster, the mongos instances provide the interface between the client applications and the sharded cluster. The mongos instances route queries and write operations to the shards. From the perspective of the application, a mongos instance behaves identically to any other MongoDB instance.

mongos instance ๋ผ๊ณ  Document ์—์„œ๋Š” ์„ค๋ช…ํ•˜๋Š”๋ฐ ์ƒค๋”ฉ๋œ ๋…ธ๋“œ(machine)๋ผ๊ณ  ์ƒ๊ฐํ•˜๋ฉด ์‰ฌ์›€.
์ƒค๋”ฉ๋œ ํด๋Ÿฌ์Šคํ„ฐ์˜ ๊ฒฝ์šฐ mongos ์ธ์Šคํ„ด์Šค๋Š” ํด๋ผ์ด์–ธํŠธ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜๊ณผ ์ƒค๋”ฉ๋œ ํด๋Ÿฌ์Šคํ„ฐ ๊ฐ„์˜ ์ธํ„ฐํŽ˜์ด์Šค ์ œ๊ณต.
mongos ์ธ์Šคํ„ด์Šค๋Š” ์ฟผ๋ฆฌ ๋ฐ ์“ฐ๊ธฐ ์ž‘์—…์„ ์ƒค๋“œ๋กœ ๋ผ์šฐํŒ….
์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ๊ด€์ ์—์„œ mongos ์ธ์Šคํ„ด์Šค๋Š” ๋‹ค๋ฅธ MongoDB ์ธ์Šคํ„ด์Šค์™€ ๋™์ผํ•˜๊ฒŒ ์ž‘๋™!

  • ๊ทผ๋ฐ ์š”๊ธฐ์„œ ์ƒค๋”ฉ์ด๋ž€?
    ์ƒค๋”ฉ์€ ๋ฐ์ดํ„ฐ๋ฅผ ์—ฌ๋Ÿฌ ์„œ๋ฒ„์— ๋ถ„์‚ฐํ•ด์„œ ์ €์žฅํ•˜๊ณ  ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐ์ˆ ์„ ๋œปํ•จ! ๋ณต์ œ(Replication)์™€์˜ ์ฐจ์ด์ ์ด ์žˆ๋‹ค๋ฉด ๋ณต์ œ๋Š” ๊ณ ๊ฐ€์šฉ์„ฑ์„ ์œ„ํ•œ ์†”๋ฃจ์…˜, ์ƒค๋”ฉ์€ ๋ถ„์‚ฐ์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•œ ์†”๋ฃจ์…˜! (๋ชฝ๊ณ ๋””๋น„์—์„œ๋Š” ๊ณ ๊ฐ€์šฉ์„ฑ๊ณผ ๋Œ€์šฉ๋Ÿ‰ ๋ถ„์‚ฐ ์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•ด ๋ณต์ œ+์ƒค๋”ฉ ๋ชจ๋‘ ์‚ฌ์šฉ!)
  • ๋ถ„์‚ฐ์ฒ˜๋ฆฌํ•˜๋Š” ๋ฐฉ๋ฒ•์€ 2๊ฐ€์ง€ vertical scaling(์ˆ˜์งํ™•์žฅ), horizontal scaling(์ˆ˜ํ‰ํ™•์žฅ)! ๋ชฝ๊ณ ๋””๋น„์—์„œ๋Š” ์ƒค๋”ฉ์„ ํ†ตํ•ด ์ˆ˜ํ‰ํ™•์žฅ์„ ์ง€์›

3) mongosh

The MongoDB Shell, mongosh, is a fully functional JavaScript and Node.js 14.x REPL environment for interacting with MongoDB deployments. You can use the MongoDB Shell to test queries and operations directly with your database.

MongoDB shell ์ธ mongosh๋Š” MongoDB ๋ฐฐํฌ์™€ ์ƒํ˜ธ ์ž‘์šฉํ•˜๊ธฐ ์œ„ํ•œ ๋ชจ๋“  ๊ธฐ๋Šฅ์„ ๊ฐ–์ถ˜ JavaScript ๋ฐ Node.js 14.x REPL ํ™˜๊ฒฝ.
MongoDB ์…ธ์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์—์„œ ์ง์ ‘ ์ฟผ๋ฆฌ ๋ฐ ์ž‘์—….

๐Ÿค SQL vs MongoDB ๐Ÿค

SQL์—์„œ ์“ฐ๋Š” ๊ฐœ๋… ๋ฐ ์šฉ์–ด, MongoDB ์—์„œ ์“ฐ๋Š” ์šฉ์–ด ๋ฐ ๊ฐœ๋…์ด ๋น„์Šทํ•˜๋ฉด์„œ ๊ฝค ๋‹ค๋ฅด๋‹น ! ์ •๋ฆฌ๋ฅผ ํ•ด๋ณผ๊นŒ....?๐Ÿฅ

  • ๋จผ์ €, MongoDB์—์„œ๋Š” table์„ collection์ด๋ผ๊ณ  ๋ถ€๋ฅธ๋‹ค. column๋ช…๊ณผ row๋ช…๋„ ๋‹ค๋ฅด๋‹ค. ์š”๋Ÿฐ ๊ฒƒ๋“ค์€ ๊ธˆ๋ฐฉ ์ ์‘ ํ•  ๊ฒƒ ๊ฐ™๋‹ค !
  • MySQL์—์„œ server๋ฅผ mysqld, database client๋ฅผ mysql์ด๋ผ๊ณ  ๋ถˆ๋ €๋‹ค๋ฉด, MongoDB์—์„œ๋Š” server๋ฅผ mongod, database client๋ฅผ mongosh๋ผ๊ณ  ๋ถ€๋ฆ„!

1) insert

db.collection.insertOne()
db.collection.insertMany()

# ์—ฌ๊ธฐ์„œ collection์€ ํ…Œ์ด๋ธ”์„ ๋œปํ•˜๊ณ , ๊ธฐ์กด์— ์žˆ๋Š” table์ด๋ผ๋ฉด ๊ฑฐ๊ธฐ์— ๊ฐ’์ด ๋“ค์–ด๊ฐ€๊ณ  ์—†๋Š” table์ด๋ผ๋ฉด ์ƒˆ๋กœ ์ƒ์„ฑ๋˜์–ด์„œ ๋“ค์–ด๊ฐ!
# ์‹ ๊ธฐํ•œ๊ฒŒ ํ•˜๋‚˜๋งŒ ๋„ฃ๋Š” ๋ช…๋ น์–ด๊ฐ€ ๋”ฐ๋กœ, ์—ฌ๋Ÿฌ๊ฐœ ๋„ฃ๋Š” ๋ช…๋ น์–ด๊ฐ€ ๋”ฐ๋กœ์ž„!

2) read
-> find๋ผ๋Š” ํ•จ์ˆ˜๋ฅผ ํ†ตํ•ด ๋™์ž‘์„ ์ˆ˜ํ–‰

db.collection.find()

ex)
db.mango.insertOne({x:'starbucks'})
db.mango.find({x:'starbucks'}) # ์ด๊ฑด ํŠน์ • ๊ฐ’ ์กฐํšŒ

db.mango.find({}) # ์ด๊ฑด ์ „์ฒด ์กฐํšŒ

# ํ•ด๋‹น ๊ฐ’์ด ์—†์œผ๋ฉด ์•„๋ฌด๊ฒƒ๋„ ๋ฆฌํ„ด ์•ˆํ•จ

select
update
delete

์ฐธ๊ณ 1: https://docs.mongodb.com/manual/reference/program/mongod/#mongodb-binary-bin.mongod
์ฐธ๊ณ 2: https://junghwanta.tistory.com/30?category=857330

profile
๊ฐœ๋ฐœ ๊ธฐ๋ก

0๊ฐœ์˜ ๋Œ“๊ธ€