例外目次
VMWare のふしぎWindows 上で VMWare を動かして CIFS を使っているときに VM を一時停止すると CIFS が同期されなくなってしまい、停止から復帰するときに不可解なエラー ("The Mongo object has not been correctly initialized by its constructor") が発生します。 Windows 共有を常にマウントさせるようにするとこの問題は発生せず、 自由に一時停止・再開をすることができます。 Windows 共有を常にマウントさせるには、次のコマンドを実行します。 $ sudo update-rc.d -f umountnfs.sh remove $ sudo update-rc.d umountnfs.sh stop 15 0 6 . 最新情報については、 » Ubuntu のドキュメント を参照ください。 MongoException クラスはじめにMongo のデフォルトの例外です。 さまざまなエラー条件を扱います。最終的にはより詳細な例外にたどり着きますが、 それらもすべて MongoException を継承しています。
クラス概要MongoException
class MongoException
extends
Exception
{
}MongoResultException クラスはじめにMongoResultException は ( MongoCollection::findAndModify など) いくつかのコマンドヘルパーで、失敗した場合にスローする例外です。 元の結果ドキュメントは MongoResultException::getDocument で取得できます。 クラス概要MongoResultException
class MongoResultException
extends
MongoException
{
/* プロパティ */
public
$document
;
/* 継承したプロパティ */
protected
string
$message
;
protected
int
$code
;
protected
string
$file
;
protected
int
$line
;
/* メソッド */
public array getDocument
( void
)
}プロパティ
MongoCursorException クラスはじめにカーソルへの不正なアクセスや応答を受け取る際のエラーが原因です。 このエラーが発生するのは、単なるクエリではなく結果を受け取るリクエストであることに注意しましょう。 書き込みやコマンド、あるいはその他何らかの情報をデータベースに送って結果を待つ操作では MongoCursorException をスローすることがあります。 唯一の例外は new MongoClient() (新しい接続の作成) で、これは MongoConnectionException しかスローしません。 このクラスはエラーメッセージを返します。 このメッセージを見れば、問題の調査の助けになり、 エラーコードに関連付けられた原因もわかります。 たとえば、次のように同じ _id のドキュメントを 2 件追加してみましょう。
<?php error message: E11000 duplicate key error index: foo.bar.$_id_ dup key: { : 1 } error code: 11000 よくあるエラーとそのコード、そして原因をまとめました。
データベースから渡されたエラークエリの実行時に発生したデータベースのエラーは、常に MongoCursorExceptions を発生させなければなりません。 エラーメッセージとエラーコードはデータベースから直接送られるので、 対応するエラーをデータベースのログから見つけることができます。 一般的なデータベースエラーをいくつかまとめました。
クラス概要MongoCursorException
class MongoCursorException
extends
MongoException
{
}MongoCursorTimeoutException クラスはじめにクエリのタイムアウトで発生します。 この例外がスローされるようになるまでの時間の長さを設定することができます。 そのためには、MongoCursor::timeout をカーソルで実行するか、 あるいは MongoCursor::$timeout を設定します。 静的変数を設定する方法は、データベースコマンドや MongoCollection::findOne のようなクエリで便利です。 これらはどちらもカーソルの内部で暗黙的に使うからです。 クラス概要MongoCursorTimeoutException
class MongoCursorTimeoutException
extends
MongoCursorException
{
}MongoConnectionException クラスはじめにドライバがデータベースへの接続に失敗した場合にスローします。 エラーメッセージにはさまざまなものがあり、 接続時にどんな問題が発生したのかを調べるために役立ちます。 以下にエラーメッセージの例を示します。
これら以外のメッセージが出た場合、おそらくそれは C のソケットからのエラーです。 主な原因についてはウェブを検索して調べましょう。 クラス概要MongoConnectionException
class MongoConnectionException
extends
MongoException
{
}MongoGridFSException クラスはじめにデータベースのファイルの読み書きでエラーが発生した場合にスローします。 クラス概要MongoGridFSException
class MongoGridFSException
extends
MongoException
{
}エラーコード
The MongoDuplicateKeyException classはじめにThrown when attempting to insert a document into a collection which already contains the same values for the unique keys. クラス概要MongoDuplicateKeyException
class MongoDuplicateKeyException
extends
MongoWriteConcernException
{
/* 継承したプロパティ */
protected
string
$message
;
protected
int
$code
;
protected
string
$file
;
protected
int
$line
;
/* 継承したメソッド */
public array MongoWriteConcernException::getDocument
( void
)
}例例1 Catching MongoDuplicateKeyException
<?php 上の例の出力は、 たとえば以下のようになります。 localhost:27017: insertDocument :: caused by :: 11000 E11000 duplicate key error index: test.test.$_id_ dup key: { : 1 } The MongoProtocolException classはじめに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
class MongoProtocolException
extends
MongoException
{
/* 継承したプロパティ */
protected
string
$message
;
protected
int
$code
;
protected
string
$file
;
protected
int
$line
;
}例例2 Catching MongoProtocolException Running the following example against MongoDB prior to 2.6.0 will throw an MongoProtocolException
<?php 上の例の出力は、 たとえば以下のようになります。 Current primary does not have a Write API The MongoExecutionTimeoutException classはじめにThrown when a operation times out server side (i.e. in MongoDB). To configure the operation timeout threshold, use MongoCursor::maxTimeMS or the "maxTimeMS" command option. クラス概要MongoExecutionTimeoutException
class MongoExecutionTimeoutException
extends
MongoException
{
/* 継承したプロパティ */
protected
string
$message
;
protected
int
$code
;
protected
string
$file
;
protected
int
$line
;
}The MongoWriteConcernException classはじめにMongoWriteConcernException is thrown when a write fails. See Write Concerns for how to set failure thresholds. Prior to MongoDB 2.6.0, the » getLastError command would determine whether a write failed. クラス概要MongoWriteConcernException
class MongoWriteConcernException
extends
MongoCursorException
{
/* 継承したプロパティ */
protected
string
$message
;
protected
int
$code
;
protected
string
$file
;
protected
int
$line
;
/* メソッド */
public array getDocument
( void
)
/* 継承したメソッド */
public string MongoCursorException::getHost
( void
)
} |