You are here

public function KeyValueStore::rename in MongoDB 8.2

Renames a key.

WARNING: non-transactional beyond the trivial key === new_key case.

Parameters

string $key: The key to rename.

string $newKey: The new key name.

Overrides KeyValueStoreInterface::rename

File

modules/mongodb_storage/src/KeyValueStore.php, line 176

Class

KeyValueStore
Class KeyValueStore provides a KeyValueStore as a MongoDB collection.

Namespace

Drupal\mongodb_storage

Code

public function rename($key, $newKey) {
  $stringKey = $this
    ->stringifyKey($key);
  $stringNew = $this
    ->stringifyKey($newKey);
  if ($stringKey === $stringNew) {
    return;
  }
  $value = $this
    ->get($stringKey);
  $this
    ->setIfNotExists($stringNew, $value);
  $this
    ->delete($stringKey);
}