
MongoDBBSONDocument::__construct 메소드를 사용하여 BSON 문서를 생성하는 기본적인 방법은 다음과 같습니다.
#hostingforum.kr
php
use MongoDBBSONUTCDateTime;
use MongoDBBSONObjectId;
$document = new MongoDBBSONDocument([
'_id' => new ObjectId(),
'name' => 'John Doe',
'age' => 30,
'created_at' => new UTCDateTime(),
]);
BSON 문서의 필드에 default 값을 설정하는 방법은 다음과 같습니다.
#hostingforum.kr
php
use MongoDBBSONUTCDateTime;
use MongoDBBSONObjectId;
$document = new MongoDBBSONDocument([
'_id' => new ObjectId(),
'name' => 'John Doe',
'age' => 30,
'created_at' => new UTCDateTime(),
'email' => ['default' => 'john.doe@example.com'],
]);
BSON 문서의 필드에 nullable 값을 설정하는 방법은 다음과 같습니다.
#hostingforum.kr
php
use MongoDBBSONUTCDateTime;
use MongoDBBSONObjectId;
$document = new MongoDBBSONDocument([
'_id' => new ObjectId(),
'name' => 'John Doe',
'age' => 30,
'created_at' => new UTCDateTime(),
'email' => ['type' => 'string', 'nullable' => true],
]);
이러한 예제를 통해 MongoDBBSONDocument::__construct 메소드를 사용하여 BSON 문서를 생성하고 필드에 default 값을 설정하는 방법 및 nullable 값을 설정하는 방법을 이해할 수 있습니다.
2025-05-19 04:10