You are here

public function KeyValueStore::getMultiple in MongoDB 8.2

Returns the stored key/value pairs for a given set of keys.

Parameters

array $keys: A list of keys to retrieve.

Return value

array An associative array of items successfully returned, indexed by key. Core until 8.5 does not specify what to return for non-existing keys, so this implementation chooses not to include the non-existing keys in the result set.

Overrides KeyValueStoreInterface::getMultiple

See also

KeyValueStoreInterface::getMultiple()

File

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

Class

KeyValueStore
Class KeyValueStore provides a KeyValueStore as a MongoDB collection.

Namespace

Drupal\mongodb_storage

Code

public function getMultiple(array $keys) {
  $stringKeys = array_map([
    $this,
    'stringifyKey',
  ], $keys);
  $selector = [
    '_id' => [
      '$in' => $stringKeys,
    ],
  ];
  $cursor = $this->mongoDbCollection
    ->find($selector, static::LEGACY_TYPE_MAP);
  $docs = [];
  foreach ($cursor as $doc) {
    $id = $doc['_id'];
    $docs[$id] = unserialize($doc['value']);
  }
  return $docs;
}