@@ -652,7 +652,6 @@ public function createIndex(string $collection, string $id, string $type, array
652652
653653 $ indexes = [];
654654 $ options = [];
655-
656655 $ indexes ['name ' ] = $ id ;
657656
658657 // If sharedTables, always add _tenant as the first key
@@ -661,15 +660,15 @@ public function createIndex(string $collection, string $id, string $type, array
661660 }
662661
663662 foreach ($ attributes as $ i => $ attribute ) {
664- $ attribute = $ this ->filter ($ this ->getInternalKeyForAttribute ($ attribute ));
663+ $ attributes [ $ i ] = $ this ->filter ($ this ->getInternalKeyForAttribute ($ attribute ));
665664 $ orderType = $ this ->getOrder ($ this ->filter ($ orders [$ i ] ?? Database::ORDER_ASC ));
666- $ indexes ['key ' ][$ attribute ] = $ orderType ;
665+ $ indexes ['key ' ][$ attributes [ $ i ] ] = $ orderType ;
667666
668667 switch ($ type ) {
669668 case Database::INDEX_KEY :
670669 break ;
671670 case Database::INDEX_FULLTEXT :
672- $ indexes ['key ' ][$ attribute ] = 'text ' ;
671+ $ indexes ['key ' ][$ attributes [ $ i ] ] = 'text ' ;
673672 break ;
674673 case Database::INDEX_UNIQUE :
675674 $ indexes ['unique ' ] = true ;
@@ -1168,7 +1167,7 @@ public function createOrUpdateDocuments(string $collection, string $attribute, a
11681167 $ attributes ['_permissions ' ] = $ document ->getPermissions ();
11691168
11701169 if (!empty ($ document ->getSequence ())) {
1171- $ attributes ['_id ' ] = new ObjectId ( $ document ->getSequence () );
1170+ $ attributes ['_id ' ] = $ document ->getSequence ();
11721171 }
11731172
11741173 if ($ this ->sharedTables ) {
@@ -1204,6 +1203,13 @@ public function createOrUpdateDocuments(string $collection, string $attribute, a
12041203 $ update = [
12051204 '$set ' => $ record
12061205 ];
1206+
1207+ // Add UUID7 _id for new documents in upsert operations
1208+ if (empty ($ document ->getSequence ())) {
1209+ $ update ['$setOnInsert ' ] = [
1210+ '_id ' => $ this ->client ->createUuid ()
1211+ ];
1212+ }
12071213 }
12081214
12091215 $ operations [] = [
@@ -1358,7 +1364,7 @@ public function deleteDocuments(string $collection, array $sequences, array $per
13581364 $ name = $ this ->getNamespace () . '_ ' . $ this ->filter ($ collection );
13591365
13601366 foreach ($ sequences as $ index => $ sequence ) {
1361- $ sequences [$ index ] = new ObjectId ( $ sequence) ;
1367+ $ sequences [$ index ] = $ sequence ;
13621368 }
13631369
13641370 $ filters = $ this ->buildFilters ([new Query (Query::TYPE_EQUAL , '_id ' , $ sequences )]);
@@ -1512,7 +1518,7 @@ public function find(string $collection, array $queries = [], ?int $limit = 25,
15121518
15131519 $ tmp = $ cursor [$ originalPrev ];
15141520 if ($ originalPrev === '$sequence ' ) {
1515- $ tmp = new ObjectId ( $ tmp) ;
1521+ $ tmp = $ tmp ;
15161522 }
15171523
15181524 $ andConditions [] = [
@@ -1523,8 +1529,6 @@ public function find(string $collection, array $queries = [], ?int $limit = 25,
15231529 $ tmp = $ cursor [$ originalAttribute ];
15241530
15251531 if ($ originalAttribute === '$sequence ' ) {
1526- $ tmp = new ObjectId ($ tmp );
1527-
15281532 /** If there is only $sequence attribute in $orderAttributes skip Or And operators **/
15291533 if (count ($ orderAttributes ) === 1 ) {
15301534 $ filters [$ attribute ] = [
@@ -1594,7 +1598,7 @@ private function getMongoTypeCode(string $appwriteType): string
15941598 Database::VAR_BOOLEAN => 'bool ' ,
15951599 Database::VAR_DATETIME => 'date ' ,
15961600 Database::VAR_ID => 'string ' ,
1597- Database::VAR_OBJECT_ID => 'objectId ' ,
1601+ Database::VAR_UUID7 => 'string ' ,
15981602 default => 'string '
15991603 };
16001604 }
@@ -1792,7 +1796,7 @@ protected function replaceChars(string $from, string $to, array $array): array
17921796 unset($ result ['$id ' ]);
17931797 }
17941798 if (array_key_exists ('$sequence ' , $ array )) {
1795- $ result ['_id ' ] = new ObjectId ( $ array ['$sequence ' ]) ;
1799+ $ result ['_id ' ] = $ array ['$sequence ' ];
17961800 unset($ result ['$sequence ' ]);
17971801 }
17981802 if (array_key_exists ('$tenant ' , $ array )) {
@@ -1842,7 +1846,7 @@ protected function buildFilter(Query $query): array
18421846 $ query ->setAttribute ('_id ' );
18431847 $ values = $ query ->getValues ();
18441848 foreach ($ values as $ k => $ v ) {
1845- $ values [$ k ] = new ObjectId ( $ v ) ;
1849+ $ values [$ k ] = $ v ;
18461850 }
18471851 $ query ->setValues ($ values );
18481852 } elseif ($ query ->getAttribute () === '$createdAt ' ) {
@@ -2400,7 +2404,7 @@ protected function execute(mixed $stmt): bool
24002404 */
24012405 public function getIdAttributeType (): string
24022406 {
2403- return Database::VAR_OBJECT_ID ;
2407+ return Database::VAR_UUID7 ;
24042408 }
24052409
24062410 /**
0 commit comments