
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