๋ฐ˜์‘ํ˜•

sort 1

[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
๋ฐ˜์‘ํ˜•