Modified: phpdoc/ja/trunk/reference/mongo/mongocollection/ensureindex.xml =================================================================== --- phpdoc/ja/trunk/reference/mongo/mongocollection/ensureindex.xml 2014-05-08 21:56:31 UTC (rev 333502) +++ phpdoc/ja/trunk/reference/mongo/mongocollection/ensureindex.xml 2014-05-08 23:25:06 UTC (rev 333503) @@ -1,12 +1,12 @@ - + MongoCollection::ensureIndex - 指定したフィールドにインデックスを作成する (すでに存在する場合は何もしない) + 指定したフィールドが存在しない場合にインデックスを作成する @@ -24,14 +24,23 @@ - このメソッドは、コレクション上の指定されたフィールドにインデックスを作成します。 - キーの指定方法は、単一のフィールド名を文字列で指定するか - あるいはフィールド名とソート方向を対応させた配列でも指定できます。 + コレクション上の指定されたフィールドが存在しない場合に、インデックスを作成します。 + フィールドのインデックスは、方向 (昇順あるいは降順) で指定するか、 + あるいは特定の型 (text, geospatial, hashed) で指定できます。 + + + This method will use the + createIndexes + database command when communicating with MongoDB 2.6+. For previous database + versions, the method will perform an insert operation on the + special system.indexes collection. + + - - &reftitle.parameters; + + &reftitle.parameters; @@ -41,108 +50,48 @@ インデックスをソートするフィールドの配列。配列の各要素のキーがフィールド名、 - そして昇順の場合は 1、降順の場合は -1 - を値に指定します。 + 値には、方向あるいは index type. + を指定します。方向を指定する場合は、昇順なら 1、降順なら + -1 と指定します。 - + options - このパラメータは - array("optionname" => <boolean>, ...) - 形式の連想配列で、現在サポートしているオプションは次の通りです。 + An array of options for the index creation. Currently available options + include: + &mongo.index.parameters.unique; + &mongo.index.parameters.dropdups; + &mongo.index.parameters.sparse; + &mongo.index.parameters.expireafterseconds; + &mongo.index.parameters.name; + &mongo.writes.parameters.sockettimeoutms; + + + + The following option may be used with MongoDB 2.6+: + + &mongo.command.parameters.maxtimems; + + + + The following options may be used with MongoDB versions before 2.6: + &mongo.writes.parameters.writeconcern; - - - "unique" - - - 一意なインデックスを作ります。 - - - - そのフィールドを持たないドキュメントが複数ある場合は、 - そこに一意なインデックスを作成することはできません。 - フィールドが存在しないときは事実上そのフィールドは - &null; ということになり、それが複数存在すると既に一意ではなくなっているからです。 - スパースなインデキシングを使えばこれを回避できるかもしれません。 - そのフィールドを持たないドキュメントをインデックスしないようになるからです。 - - - - - - "dropDups" - - - 一意なインデックスを作ったときに重複する値が存在すれば、 - ひとつを除いてその他すべてを削除します。 - - - - - "sparse" - - - スパースなインデックスを作り、そのフィールドを含むドキュメントだけを含めるようにします。 - このオプションは、単一フィールドインデックスでしか使えません。 - - - - - "expireAfterSeconds" - - - このオプションの値には、ドキュメントが期限切れになって自動的にコレクションから削除されるようになるまでの秒数を指定します。 - このオプションは、単一フィールドインデックスかつそのフィールドに - MongoDate の値を含む場合しか使えません。 - - - この機能が使えるのは MongoDB 2.2 以降です。詳細は - Expire Data from Collections by Setting TTL - を参照ください。 - - - - - "background" - - - デフォルトではインデックスの作成はブロック操作になり、 - 処理が完了するまではデータベース上で他の操作を進めることができません。 - このオプションを &true; にすると、 - インデックスの作成をバックグラウンドで行うようになり、 - 作成中にも他の操作ができるようになります。 - - - - MongoDB 2.1.0 より前のバージョンでのインデックス作成は、 - セカンダリへのレプリケートのときには - このオプションの値にかかわらずバックグラウンド処理になりませんでした。 - 詳細は - Building Indexes with Replica Sets - を参照ください。 - - - - - - "name" - - - このオプションを指定すると、ドライバーがインデックス名を作るときのアルゴリズムを上書きし、 - 好きな名前を指定できます。 - これは、多くのキーにインデックスをつけるときに「インデックス名が長すぎる」 - と Mongo に言われた場合などに有用です。 - - - &mongo.writes.parameters.timeout; + &mongo.writes.parameters.writeconcerntimeoutms; + + + + The following options are deprecated and should no longer be used: + &mongo.writes.parameters.safe; + &mongo.writes.parameters.timeout; + &mongo.writes.parameters.writeconcerntimeout; @@ -154,13 +103,24 @@ &reftitle.returnvalues; - "w" オプションが設定されている場合は、 - インデックスの作成の状態を含む配列を返します。それ以外の場合は - &true; を返します。 + Returns an array containing the status of the index creation. The array + contains whether the operation succeeded ("ok"), the + number of indexes before and after the operation + ("numIndexesBefore" and + "numIndexesAfter"), and whether the collection that the + index belongs to has been created + ("createdCollectionAutomatically"). If the index already + existed and did not need to be created, a "note" field may + be present in lieu of "numIndexesAfter". - 配列のフィールドについての説明は - MongoCollection::insert を参照ください。 + With MongoDB 2.4 and earlier, a status document is only returned if the + write concern is at least + 1. Otherwise, &true; is returned. The fields in the status + document are different, except for the "ok" field, which + signals whether the index creation was successful. Additional fields are + described in the documentation for + MongoCollection::insert. @@ -177,50 +137,78 @@ + 1.5.0 + + + Renamed the "wtimeout" option to + "wTimeoutMS". Emits + E_DEPRECATED when "wtimeout" is + used. + + + Renamed the "timeout" option to + "socketTimeoutMS". Emits + E_DEPRECATED when "timeout" is + used. + + + Emits E_DEPRECATED when "safe" + is used. + + + + + 1.3.4 + Added "wtimeout" option. + + 1.3.0 - options パラメータで、boolean - だけを渡してユニークインデックスを指定することができなくなりました。 - 同じことをするには array('unique' => true) - としなければなりません。 + Added "w" option. + + The options parameter no longer accepts a + boolean to signify a unique index. Instead, this now has to be done + with array('unique' => true). + 1.2.11 - options が scalar のときに E_DEPRECATED を発行するようになりました。 + Emits E_DEPRECATED when + options is scalar. 1.2.0 - "timeout" オプションが追加されました。 + Added "timeout" option. 1.0.11 - "safe" は必要に応じてプライマリのフェイルオーバーを行うようになりました。 + The "safe" option will trigger a primary failover, + if necessary. - インデックス名 (自動生成されたものあるいは設定したもののどちらでも) - の長さが 128 バイトを超えた場合に - MongoException をスローするようになりました。 + MongoException will be thrown if the index name + (either generated or set) is longer than 128 bytes. 1.0.5 - "name" オプションで、インデックス名の作成を上書きできるようになりました。 + Added the "name" option to override index name creation. 1.0.2 - options パラメータが boolean から配列に変わりました。 - 1.0.2 より前のバージョンでは二番目のパラメータはオプションの boolean - 値で、一意なインデックスを指定するものでした。 + Changed options parameter from boolean to array. + Pre-1.0.2, the second parameter was an optional boolean value specifying + a unique index. @@ -232,84 +220,84 @@ &reftitle.errors; - インデックス名 (自動生成されたものあるいは設定したもののどちらでも) - の長さが 128 バイトを超えた場合に - MongoException をスローします - (バージョン 1.0.11 以降)。 + Throws MongoException if the index name is longer + than 128 bytes, or if the index specification is not an array. + + Throws MongoDuplicateKeyException if the server could not + create the unique index due to conflicting documents. + + + Throws MongoResultException if the server could not + create the index due to an error. + &mongo.errors.exceptions.writeconcern; &reftitle.examples; - <function>MongoCollection::ensureIndex</function> の例 + <function>MongoCollection::ensureIndex</function> example ensureIndex('x'); +// create an index on 'x' ascending +$c->ensureIndex(array('x' => 1)); -// 'y' の昇順にインデックスを作成します -$c->ensureIndex(array('y' => 1)); +// create a unique index on 'y' +$c->ensureIndex(array('y' => 1), array('unique' => true)); -// 'z' の昇順、'zz' の降順にインデックスを作成します -$c->ensureIndex(array('z' => 1, 'zz' => -1)); +// create a compound index on 'za' ascending and 'zb' descending +$c->ensureIndex(array('za' => 1, 'zb' => -1)); -// 'x' に一意なインデックスを作成します -$c->ensureIndex(array('x' => 1), array("unique" => true)); - ?> ]]> - 重複を削除する例 + Geospatial Indexing + + Mongo supports geospatial indexes, which allow you to search for documents + near a given location or within a shape. The following example creates a + geospatial index on the "loc" field: + insert(array("username" => "joeschmoe")); -$collection->insert(array("username" => "joeschmoe")); +$collection->ensureIndex(array('loc' => '2dsphere')); -/* - * インデックスの作成に失敗します。重複する値があるキーに - * 一意なインデックスを作ることはできません。 - */ -$collection->ensureIndex(array("username" => 1), array("unique" => 1)); - -/* - * インデックスの作成に成功します。ドキュメントのひとつがコレクションから削除されます。 - */ -$collection->ensureIndex(array("username" => 1), array("unique" => 1, "dropDups" => 1)); - -/* - * 一意なインデックスができたあとは、同じユーザー名を - * このように追加しようとしても失敗します。 - */ -$collection->insert(array("username" => "joeschmoe")); - ?> ]]> - - 地理空間のインデックス - - Mongo は地理空間のインデックスをサポートしています。 - これを使うと、指定した場所のそば、あるいは図形の範囲内にあるドキュメントを探すことができます。 - たとえば、"loc" フィールドに地理空間のインデックスを作るには次のようにします。 - + Drop duplicates example ensureIndex(array("loc" => "2d")); +$collection->insert(array('username' => 'joeschmoe')); +$collection->insert(array('username' => 'joeschmoe')); +/* Index creation fails, since you cannot create a unique index on a field when + * duplicates exist. + */ +$collection->ensureIndex(array('username' => 1), array('unique' => 1)); + +/* MongoDB will one of the conflicting documents and allow the unique index to + * be created. + */ +$collection->ensureIndex(array('username' => 1), array('unique' => 1, 'dropDups' => 1)); + +/* We now have a unique index and subsequent inserts with the same username will + * fail. + */ +$collection->insert(array('username' => 'joeschmoe')); + ?> ]]> @@ -320,13 +308,13 @@ &reftitle.seealso; MongoCollection::createIndex + + The MongoDB + index and + index type + documentation. + - - MongoDB コアドキュメントの - vanilla indexes および - geospatial indexes - を参照ください。 -