
setTypeMap 메서드는 데이터 타입 매핑을 설정하는 데 사용됩니다. 데이터 타입 매핑 객체는 Map 인터페이스를 구현해야 하며, 키는 MongoDB의 데이터 타입을 나타내고 값은 PHP의 데이터 타입을 나타냅니다.
예를 들어, 다음 코드는 Integer 타입을 PHP의 int 타입으로 매핑하는 데이터 타입 매핑 객체를 생성하는 방법을 보여줍니다.
#hostingforum.kr
php
use MongoDBDriverServer;
use MongoDBDriverCursor;
use MongoDBDriverBulkWrite;
use MongoDBDriverBulkWriteException;
use MongoDBDriverCursorException;
use MongoDBDriverWriteConcernException;
use MongoDBDriverWriteException;
use MongoDBDriverReadPreference;
use MongoDBDriverReadConcern;
use MongoDBDriverServerException;
use MongoDBDriverWriteConcern;
use MongoDBDriverCursorType;
$map = new class implements Map {
public function get($key) {
if ($key === Server::BSON_TYPE_INT32) {
return 'int';
}
// 다른 타입의 매핑을 추가하세요.
}
};
setTypeMap 메서드는 데이터 타입 매핑 객체를 파라미터로 전달받습니다.
#hostingforum.kr
php
$cursor = $collection->find();
$cursor->setTypeMap($map);
이러한 데이터 타입 매핑을 사용하면 MongoDB의 데이터 타입을 PHP의 데이터 타입으로 매핑할 수 있습니다.
2025-04-27 22:44