๋ฐ˜์‘ํ˜•

Database/monogodb 7

[MongoDB] ๊ฒŒ์‹œ๊ธ€ ์ฝ์Œ(read)/์•ˆ์ฝ์Œ(unread) ํ‘œ์‹œ ์ƒํƒœ ์ฒ˜๋ฆฌํ•˜๋Š” ๋ฐฉ๋ฒ•

Intro ์•ˆ๋…•ํ•˜์„ธ์š”. ์ด๋ฒˆ์‹œ๊ฐ„์—๋Š” MongoDB ๋ชฝ๊ณ ๋””๋น„์—์„œ ๊ฒŒ์‹œ๊ธ€ ์ฝ์Œ(read)/์•ˆ์ฝ์Œ(unread) ํ‘œ์‹œ์ƒํƒœ๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. How to do ์šฐ์„  ์ œ ์ƒํ™ฉ์˜ ๊ฒฝ์šฐ ๊ณต์ง€์‚ฌํ•ญ Collection(๊ฒŒ์‹œ๊ธ€ Collection๋ผ๊ณ  ๋ด๋„ ๋ฌด๋ฐฉ), ๊ทธ๋ฆฌ๊ณ  ์‚ฌ์šฉ์ž Collection์ด ์กด์žฌํ•ฉ๋‹ˆ๋‹ค. User user collection์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. _id, userId, userName ํ•„๋“œ๋ฅผ ๊ฐ–๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. { _id: user_uniqueId, userId: senderId, userName: userName } Notice notice collection์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. _id, noticeId, title, contents ํ•„๋“œ๋ฅผ ๊ฐ–๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. { _id: us..

Database/monogodb 2023.02.11

[MongoDB] ๋ชฝ๊ณ ๋””๋น„ ๋ฒ„์ „ ํ™•์ธ ๋ฐฉ๋ฒ•, ๋ช…๋ น์–ด ์•Œ์•„๋ณด๊ธฐ

Intro ์•ˆ๋…•ํ•˜์„ธ์š”. ์ด๋ฒˆ ์‹œ๊ฐ„์—๋Š” ๋ชฝ๊ณ ๋””๋น„ ๋ฒ„์ „์„ ํ™•์ธํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. How to check MongoDB Version #1 db.version() #2 $ mongod --version https://stackoverflow.com/questions/38160412/mongodb-how-to-find-the-exact-version-of-installed-mongodb

Database/monogodb 2023.02.10

[MongoDB] ๋ชฝ๊ณ  DB $set ์—…๋ฐ์ดํŠธ ์‚ฌ์šฉ ์˜ˆ์ œ, ํŠน์ • field ์—…๋ฐ์ดํŠธ ํ•˜๊ธฐ

Intro ์•ˆ๋…•ํ•˜์„ธ์š”. ์ด๋ฒˆ ์‹œ๊ฐ„์—๋Š” MongoDB์˜ $set ์—…๋ฐ์ดํŠธ์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. $set MongoDB์—์„œ๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ์ˆ˜์ •ํ•˜๊ธฐ ์œ„ํ•ด update ๋ฉ”์†Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํŠน์ • ํ•„๋“œ๋งŒ ์—…๋ฐ์ดํŠธ ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” $set ์—ฐ์‚ฐ์ž๋ฅผ ์‚ฌ์šฉํ•˜๋Š”๋ฐ์š”, ํ•œ๋ฒˆ ์˜ˆ์‹œ๋ฅผ ์‚ดํŽด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. Examples ์˜ˆ๋ฅผ ๋“ค์–ด ์•„๋ž˜์˜ ์ปฌ๋ ‰์…˜์ด ์กด์žฌํ•œ๋‹ค๊ณ  ๊ฐ€์ •ํ•ด๋ด…์‹œ๋‹ค. db.products.insertOne( { _id: 100, quantity: 250, instock: true, reorder: false, details: { model: "14QQ", make: "Clothes Corp" }, tags: [ "apparel", "clothing" ], ratings: [ { by: "Customer007", ..

Database/monogodb 2023.02.04

[MongoDB] ์ƒค๋”ฉ(Sharding)์ด๋ž€ ๋ฌด์—‡์ธ๊ฐ€? ๋ชฝ๊ณ ๋””๋น„ ์ƒค๋”ฉ ๊ตฌ์„ฑ์š”์†Œ ์‚ดํŽด๋ณด๊ธฐ

Intro ์•ˆ๋…•ํ•˜์„ธ์š”. ์ด๋ฒˆ ์‹œ๊ฐ„์—๋Š” MonogoDB ๋ชฝ๊ณ ๋””๋น„์˜ ์ƒค๋”ฉ์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. What is Sharding? ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ƒค๋”ฉ์€ ์—ฌ๋Ÿฌ ์‹œ์Šคํ…œ์— ๋Œ€๊ทœ๋ชจ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ์ €์žฅํ•˜๋Š” ํ”„๋กœ์„ธ์Šค์ž…๋‹ˆ๋‹ค. ๋‹จ์ผ ์‹œ์Šคํ…œ ๋˜๋Š” ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์„œ๋ฒ„๋Š” ์ œํ•œ๋œ ์–‘์˜ ๋ฐ์ดํ„ฐ๋งŒ ์ €์žฅํ•˜๊ณ  ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ์ƒค๋”ฉ์€ ๋ฐ์ดํ„ฐ๋ฅผ ์ƒค๋“œ๋ผ๊ณ  ํ•˜๋Š” ๋” ์ž‘์€ ์ฒญํฌ๋กœ ๋ถ„ํ• ํ•˜๊ณ  ์—ฌ๋Ÿฌ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์„œ๋ฒ„์— ์ €์žฅํ•จ์œผ๋กœ์จ ์ด๋Ÿฌํ•œ ํ•œ๊ณ„๋ฅผ ๊ทน๋ณตํ•ฉ๋‹ˆ๋‹ค. Why? ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์„ฑ์žฅํ•จ์— ๋”ฐ๋ผ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์‚ฌ์šฉ์ž ์ˆ˜์™€ ์ €์žฅํ•˜๋Š” ๋ฐ์ดํ„ฐ์˜ ์–‘์ด ์‹œ๊ฐ„์ด ์ง€๋‚จ์— ๋”ฐ๋ผ ์ฆ๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. ๋ฐ์ดํ„ฐ ๋ณผ๋ฅจ์ด ๋„ˆ๋ฌด ์ปค์ง€๊ณ  ๋„ˆ๋ฌด ๋งŽ์€ ์‚ฌ์šฉ์ž๊ฐ€ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์‚ฌ์šฉํ•˜์—ฌ ๋™์‹œ์— ์ •๋ณด๋ฅผ ์ฝ๊ฑฐ๋‚˜ ์ €์žฅํ•˜๋ ค๊ณ  ํ•˜๋ฉด ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ๋ณ‘๋ชฉ ํ˜„์ƒ์ด ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค. ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ๋Š๋ ค..

Database/monogodb 2023.01.24

[MongoDB] ์˜ค๋ฆ„์ฐจ์ˆœ(Ascending)๊ณผ ๋‚ด๋ฆผ์ฐจ์ˆœ(Descending)์˜ ์˜๋ฏธ, ๋ชฝ๊ณ ๋””๋น„์—์„œ ์ •๋ ฌ sort ํ•˜๋Š” ๋ฐฉ๋ฒ•

Intro ์•ˆ๋…•ํ•˜์„ธ์š”. ์ด๋ฒˆ ์‹œ๊ฐ„์—๋Š” MongoDB ๋ชฝ๊ณ ๋””๋น„์—์„œ ์ฟผ๋ฆฌ๋ฅผ ์ •๋ ฌํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ์šฐ์„  ๊ทธ์— ์•ž์„œ ์˜ค๋ฆ„์ฐจ์ˆœ๊ณผ ๋‚ด๋ฆผ์ฐจ์ˆœ์˜ ์˜๋ฏธ์— ๋Œ€ํ•ด ํ•จ๊ป˜ ์‚ดํŽด๋ณด๋„๋ก ํ•ด์š”. Ascending / ์˜ค๋ฆ„์ฐจ์ˆœ ์˜ค๋ฆ„์ฐจ์ˆœ (Ascending)์€ smallest to largest ๋กœ, ์ž‘์€ ์ˆซ์ž์—์„œ ํฐ ์ˆซ์ž๋กœ ์ •๋ ฌํ•˜๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. (ex. 1 -> 2 -> 3 -> 4 -> 5) Descending / ๋‚ด๋ฆผ์ฐจ์ˆœ ๋‚ด๋ฆผ์ฐจ์ˆœ (Descending)์€ largest to smallest๋กœ, ํฐ ์ˆซ์ž์—์„œ ์ž‘์€ ์ˆซ์ž๋กœ ์ •๋ ฌํ•˜๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. (ex. 5 -> 4 -> 3 -> 2 -> 1) How to sort in MongoDB MongoDB์—์„œ 1์€ ์˜ค๋ฆ„์ฐจ์ˆœ, -1์€ ๋‚ด๋ฆผ์ฐจ์ˆœ ์ •๋ ฌ์— ํ•ด๋‹นํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ..

Database/monogodb 2023.01.14

[MongoDB] ํ”„๋กœ์ ์…˜ (Projection) ์ด๋ž€? projection query ์‚ฌ์šฉ๋ฒ•

Intro MongoDB์˜ ํ”„๋กœ์ ์…˜์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. What is projection? MongoDB์—์„œ projection(ํ”„๋กœ์ ์…˜)์€ ํ•œ document ์ „์ฒด๋ฅผ ์„ ํƒํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ, ํŠน์ • ํ•„์š”ํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ์„ ํƒํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด document๊ฐ€ 3๊ฐœ์˜ ํ•„๋“œ๋ฅผ ๊ฐ–๊ณ  ์žˆ์„ ๋•Œ, 1๊ฐœ์˜ ํ•„๋“œ๋งŒ ๋ณด์—ฌ์ฃผ๊ณ  ์‹ถ๋‹ค๋ฉด 1๊ฐœ์˜ ํ•„๋“œ์— ๋Œ€ํ•ด ํ”„๋กœ์ ์…˜์„ ๊ฑธ์–ด์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค. Projection parameter MongoDB์—์„œ find๋กœ query๋ฅผ ๊ฑธ์–ด์ค„ ๋•Œ ํŒŒ๋ผ๋ฏธํ„ฐ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. db.$(collection name).find( {filter condition} , {projection parameter}) Example ๋‹ค์Œ์€ projectType์ด "GO"์ด๋ฉด์„œ, projectName๊ณผ, st..

Database/monogodb 2022.12.20

[MongoDB] Read Preference ์˜๋ฏธ์™€ ์ข…๋ฅ˜

Intro mongodb์˜ read preference์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. Read Preference? read preference๋ž€ mongo db์—์„œ replica set ์„ค์ • ์‹œ primary, secondary์— ๋Œ€ํ•œ ์„ค์ •์ž…๋‹ˆ๋‹ค. ์ด๋ฅผ ์œ„ํ•ด mongo db๋Š” 5๊ฐ€์ง€ ๋ฐฉ๋ฒ•์„ ์ง€์›ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. Read Preference ModeDescription primary Default mode. All operations read from the current replica set primary. Multi-document transactions that contain read operations must use read preference primary. All operations in a give..

Database/monogodb 2022.11.16
๋ฐ˜์‘ํ˜•