jarangteam / hq

0 stars 0 forks source link

mongoDB 스키마 #2

Open lhk810 opened 1 year ago

lhk810 commented 1 year ago
db.createCollection(
  "user",
  {validator:{
    $jsonSchema: {
      required: ["email", "name", "password", "point"],
      properties: {
        email: {bsonType: "string"},
        password: {bsonType: "string"},
        name: {bsonType: "string"},
        point: {bsonType: "int"},
        achievement: {
          bsonType: "object",
          required: ["title", "achieved_at"],
          properties: {
            title: {bsonType: "string"},
            achieved_at: {bsonType: "timestamp"}
          }
        }
      }
    }
  }
})

db.createCollection(
  "jarang",
  {validator:{
    $jsonSchema: {
      required: ["user_id", "title", "content"],
      properties: {
        user_id: {
           bsonType: "objectId",
        },
        title: {bsonType: "string"},
        content: {bsonType: "string"},
        reaction_count: {
          bsonType: "object",
          required: ["reaction_type", "count"],
          properties: {
            reaction_type: {bsonType: "string"},
            count: {bsonType: "int"}
          }
        }
      }
    }
  }
})

db.createCollection(
  "reaction",
  {validator:{
    $jsonSchema:{
      required: ["jarang_id", "user_id", "reaction_type", "status"],
      properties: {
        jarang_id:{
          bsonType: "objectId",
        },
        user_id: {
          bsonType: "objectId",
        },
        reaction_type: {bsonType: "string"},
        status: {bsonType: "string"}
      }
    }
  }
})
lhk810 commented 1 year ago

이제 샘플 데이터를 만드는 명령어 역시 준비해두고, aws mongodb에 스키마 생성 및 데이터 삽입을 진행합니다.