라이브러리
[PHP] MongoDBDriverCursor::next - 커서를 다음 결과로 이동합니다.
MongoDBDriverCursor::next
MongoDBDriverCursor는 MongoDB의 데이터베이스에서 데이터를 읽어오는 커서입니다. 이 커서는 MongoDB의 데이터베이스에서 데이터를 읽어오는 데 사용됩니다. MongoDBDriverCursor::next는 커서에서 다음 데이터를 읽어오는 메서드입니다.
# 사용법
MongoDBDriverCursor::next는 다음과 같이 사용할 수 있습니다.
#hostingforum.kr
php
$manager = new MongoDBDriverManager("mongodb://localhost:27017");
$db = $manager->selectDatabase('mydb');
$collection = $db->selectCollection('mycollection');
$filter = new MongoDBBSONFilter(["name" => "John"]);
$cursor = $collection->find($filter);
while ($cursor->hasNext()) {
$document = $cursor->next();
echo $document['name'] . "
";
}
# 예제
이 예제는 MongoDB의 데이터베이스에서 이름이 "John"인 데이터를 읽어오는 예제입니다.
#hostingforum.kr
php
// MongoDB Driver Manager를 생성합니다.
$manager = new MongoDBDriverManager("mongodb://localhost:27017");
// 데이터베이스와 컬렉션을 선택합니다.
$db = $manager->selectDatabase('mydb');
$collection = $db->selectCollection('mycollection');
// 필터를 생성합니다.
$filter = new MongoDBBSONFilter(["name" => "John"]);
// 커서를 생성합니다.
$cursor = $collection->find($filter);
// 커서에서 데이터를 읽어옵니다.
while ($cursor->hasNext()) {
$document = $cursor->next();
echo $document['name'] . "
";
}
// 커서를 닫습니다.
$cursor->close();
# hasNext() 메서드
MongoDBDriverCursor::next는 hasNext() 메서드가 true를 반환할 때만 데이터를 읽어올 수 있습니다. hasNext() 메서드는 커서가 다음 데이터를 읽어올 수 있는지 여부를 반환합니다.
#hostingforum.kr
php
while ($cursor->hasNext()) {
$document = $cursor->next();
echo $document['name'] . "
";
}
# close() 메서드
커서를 닫는 메서드는 close() 메서드입니다. 커서를 닫는 메서드는 커서를 닫고, 커서를 사용할 수 없게 만듭니다.
#hostingforum.kr
php
$cursor->close();
# 참고
* MongoDB Driver는 PHP 5.6 이상에서 사용할 수 있습니다.
* MongoDB Driver는 MongoDB 3.6 이상에서 사용할 수 있습니다.
* MongoDB Driver는 MongoDB의 데이터베이스에서 데이터를 읽어오는 데 사용됩니다.
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.