개발자 Q&A

개발하다 막혔다면? 여기서 질문하세요! 초보부터 고수까지, 함께 고민하고 해결하는 공간입니다. 누구나 자유롭게 질문하고 답변을 남겨보세요!

2025.04.14 01:13

MongoDBBSONDocument::fromJSON 관련 질문

목록
  • JetpackCompose마… 1일 전 2025.04.14 01:13
  • 18
    1
제가 MongoDBBSONDocument::fromJSON를 사용하여 JSON 데이터를 MongoDB document로 변환하려고 하는데,

JSON 데이터가 다음과 같은 형식을 가지고 있다고 가정할 때,

json

{

  "name": "John Doe",

  "age": 30,

  "address": {

    "street": "123 Main St",

    "city": "Anytown",

    "state": "CA",

    "zip": "12345"

  }

}



MongoDBBSONDocument::fromJSON를 사용하여 MongoDB document를 생성했을 때,

swift

let jsonData = """

{

  "name": "John Doe",

  "age": 30,

  "address": {

    "street": "123 Main St",

    "city": "Anytown",

    "state": "CA",

    "zip": "12345"

  }

}

"""



let document = try! BSONDocument(fromJSON: jsonData)



이 때, document의 address 필드가 어떻게 저장되었는지 궁금합니다.

address 필드는 MongoDB document의 nested document로 저장되었는지, 또는 flat한 형태로 저장되었는지 궁금합니다.

혹시 이에 대한 방법이나 예시를 알려주시면 감사하겠습니다.

    댓글목록

    profile_image
    나우호스팅  1일 전



    MongoDBBSONDocument::fromJSON를 사용하여 JSON 데이터를 MongoDB document로 변환할 때, address 필드는 nested document 형태로 저장됩니다.

    #hostingforum.kr
    swift
    
    let jsonData = """
    
    {
    
      "name": "John Doe",
    
      "age": 30,
    
      "address": {
    
        "street": "123 Main St",
    
        "city": "Anytown",
    
        "state": "CA",
    
        "zip": "12345"
    
      }
    
    }
    
    """
    
    
    
    let document = try! BSONDocument(fromJSON: jsonData)
    
    
    
    print(document["address"] as? BSONDocument)
    
    


    위 예제에서, document["address"]는 BSONDocument 타입의 nested document를 반환합니다.

    이러한 형태로 address 필드는 MongoDB document의 nested document로 저장됩니다.

    2025-04-14 01:13

  • 개발자 Q&A 포인트 정책
      글쓰기
      50P
      댓글
      10P
  • 전체 11,671건 / 9 페이지

검색

게시물 검색