function _mongodb_field_storage_query_value in MongoDB 7
Build a MongoDB query selector based on EntityQuery syntax.
Parameters
mixed $value: The value to which to apply the operator.
string $operator: The query operator.
string $type: The field type.
Return value
array|array[]|\MongoRegex|string|string[] The query selector.
Throws
\MongoException
1 call to _mongodb_field_storage_query_value()
- mongodb_field_storage_query in mongodb_field_storage/
mongodb_field_storage.module - Implements hook_field_storage_query().
File
- mongodb_field_storage/
mongodb_field_storage.module, line 491 - Implementation of the field storage API for MongoDB.
Code
function _mongodb_field_storage_query_value($value, $operator, $type) {
if (!isset($operator)) {
$operator = is_array($value) ? 'IN' : '=';
}
$value = _mongodb_field_storage_value($type, $value);
switch ($operator) {
case '=':
return $value;
case 'IN':
return array(
'$in' => array_values($value),
);
case 'NOT IN':
return array(
'$nin' => array_values($value),
);
case 'ALL':
return array(
'$all' => $value,
);
case '<':
return array(
'$lt' => $value,
);
case '>':
return array(
'$gt' => $value,
);
case '<=':
return array(
'$lte' => $value,
);
case '>=':
return array(
'$gte' => $value,
);
case '!=':
case '<>':
return array(
'$ne' => $value,
);
case 'STARTS_WITH':
return new MongoRegex('/^' . preg_quote($value) . '/');
case 'CONTAINS':
return new MongoRegex('/' . preg_quote($value) . '/');
case 'BETWEEN':
return array(
'$gte' => $value[0],
'$lte' => $value[1],
);
default:
throw new EntityFieldQueryException("{$operator} not implemented");
}
}