Database/NoSQL
[MongoDB] index
by lumination
2025. 6. 16.
Level 0 (Root)
+-----------------------------+
| [30 | 60] | 루트 노드 (최상위)
+-----------------------------+
/ | \
/ | \
Level 1 Level 1 Level 1
+-----------+ +-----------+ +-----------+
| [10|20] | | [40|50] | | [70|80|90]|
+-----------+ +-----------+ +-----------+
/ \ / \ / | \
/ \ / \ / | \
L2 L2 L2 L2 L2 L2 L2
------
db.users.createIndex({email : 1})
db.users.createindex({userId : 1, status : 1, createdAt : 1})
-> 정합한 예 : db.users.find({userid : 100, status : "paid"}).sort({createdAt : -1})
-> 조금 아쉬운 쿼리 : db.users.find({userid : 100, status : "paid"})
-> 잘못된 쿼리 : db.users.find({status : "paid"})