略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: MongoProtocolException

2024-12-24

The MongoProtocolException class

(PECL mongo >= 1.5.0)

简介

When talking to MongoDB 2.6.0, and later, certain operations (such as writes) may throw MongoProtocolException when the response from the server did not make sense - for example during network failure (we could read the entire response) or data corruption.

This exception is also thrown when attempting to talk newer protocols then the server supports, for example using the MongoWriteBatch when talking to a MongoDB server prior to 2.6.0.

类摘要

MongoProtocolException extends MongoException {
/* 继承的属性 */
protected string $message ;
protected int $code ;
protected string $file ;
protected int $line ;
}

范例

Example #1 Catching MongoProtocolException

Running the following example against MongoDB prior to 2.6.0 will throw an MongoProtocolException

<?php
$mc 
= new MongoClient("localhost");
$c $mc->selectCollection("test""test");

try {
    
$batch = new MongoInsertBatch($c);
} catch(
MongoProtocolException $e) {
    echo 
$e->getMessage();
}
?>

以上例程的输出类似于:

Current primary does not have a Write API
add a note add a note

User Contributed Notes

There are no user contributed notes for this page.

官方地址:https://www.php.net/manual/en/class.mongoprotocolexception.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3