본문 바로가기
[MongoDB] CRUD와 Upsert insertOne, insertManydb.users.insertOne({name : "Alice", age : 25})db.users.insertMany( {name : "Alice", age : 25}, {name : "test", position : "dev"} )------------find, findOnedb.users.find()db.users.find({age : {$gte : 25}})db.users.findOne({name : "Alice"})--------------updateOne, updateManydb.users.updateOne({name : "Alince"}, {$set : {age : 30}})db.users.updateMany({city: "Busan"}, .. 2025. 6. 16.
[MongoDB] 인덱스 설계 법칙과 쿼리 튜닝을 위한 실행 계획 분석 db.orders.createIndex({userId : 1, status : 1, createdAt : -1})db.orders.find({userId : 123, status: "paid"}).explain("executionstats")------IXSCAN : 인덱스 스캔이 발생 (제대로 사용)COLLSCAN : 전체 컬렉션을 스캔 (인덱스를 미사용)FETCH : 인덱스에서 찾은 문서를 읽었다.SROT : 인덱스를 사용해서 정렬으 하지 못했다.nReturned : 실제로 반환되는 문서의 수totalkeysExamined : 인덱스에서 검사한 엔트리의 갯수 (작을 수록 효율적)totalDocsExamined : 실제 문서를 몇개 읽었는지 (작을 수록 효율적)executionTimeMillis : l.. 2025. 6. 16.
[MongoDB] 다양한 인덱스 {_id : 1, tags : ["mongodb", "nosql", "index"]}{_id : 2 , tages : ["database", "index"]}db.users.createindex({tags : 1})"database" -> _id : 2"index" : -> _id : 1, _id : 2"mongodb" -> _id : 1"nosql" -> _id : 1--------db.users.createIndex({"creatdAt"}, {expireAfterSeconds : 3600})---------db.users.createindex({title : "text", content : "text"})-> db.users.find({$text : {$search : "mongodb index"}) 2025. 6. 16.
[MongoDB] index Level 0 (Root)+-----------------------------+| [30 | 60] | 루트 노드 (최상위)+-----------------------------+ / | \ / | \Level 1 Level 1 Level 1+-----------+ +-----------+ +-----------+| [10|20] | | [40|50] | | [70|80|90]|+-----------+ +-----------+ +-----------+ / \ / \ / | \ / \ .. 2025. 6. 16.
[MongoDB] 스키마 설계 패턴 - Key-value-array{ "_id": 1, "product": "Keyboard", "attributes": [ { "name": "color", "value": "black" }, { "name": "layout", "value": "QWERTY" } ]}- Key-value-object{ "_id": 2, "product": "Monitor", "attributes": { "resolution": "1920x1080", "size": "24in" }}------------{ "_id": ObjectId("..."), "sensorId": "sensor-101", "startTime": ISODate("2025-05-28T00:00:00Z"), "en.. 2025. 6. 16.
[MongoDB] 문서 설계와 사례 { "_id": ObjectId("..."), "title": "MongoDB 시작하기", "content": "MongoDB는 문서 지향 데이터베이스로...", "author": { "name": "김개발", "email": "kim@blog.com" }, "tags": ["MongoDB", "NoSQL", "데이터베이스"], "comments": [ { "user": "이사용자", "text": "정말 유익한 글이네요!", "date": ISODate("2023-05-20") } ], "metadata": { "views": 1250, "likes": 42, "featured": true }, "published_da.. 2025. 6. 16.