Преглед изворни кода

Skip write concern options during index creation

Andreas Braun пре 10 година
родитељ
комит
acf0e58d1c

+ 7 - 1
lib/Mongo/MongoCollection.php

@@ -591,7 +591,13 @@ class MongoCollection
         }
 
         try {
-            $this->collection->createIndex($keys, $this->convertWriteConcernOptions($options));
+            foreach (['w', 'wTimeoutMS', 'safe', 'timeout', 'wtimeout'] as $invalidOption) {
+                if (isset($options[$invalidOption])) {
+                    unset($options[$invalidOption]);
+                }
+            }
+
+            $this->collection->createIndex($keys, $options);
         } catch (\MongoDB\Driver\Exception\Exception $e) {
             throw ExceptionConverter::toLegacy($e, 'MongoResultException');
         }

+ 14 - 0
tests/Alcaeus/MongoDbAdapter/Mongo/MongoCollectionTest.php

@@ -835,6 +835,20 @@ class MongoCollectionTest extends TestCase
         $this->assertSame($expected, $this->getCollection()->createIndex(['foo' => 1]));
     }
 
+    public function testCreateIndexWithDeprecatedOptions()
+    {
+        $this->getCollection()->createIndex(['foo' => 1], ['w' => 1]);
+
+        $expected = [
+            'createdCollectionAutomatically' => false,
+            'numIndexesBefore' => 2,
+            'numIndexesAfter' => 2,
+            'note' => 'all indexes already exist',
+            'ok' => 1.0
+        ];
+        $this->assertSame($expected, $this->getCollection()->createIndex(['foo' => 1]));
+    }
+
     public function testCreateIndexTwiceWithSameName()
     {
         $this->getCollection()->createIndex(['foo' => 1], ['name' => 'test_index']);