---
title: "Starts-With Query"
url: "https://docs.ravendb.net/6.2/client-api/session/querying/text-search/starts-with-query"
version: "6.2"
language: "php"
---

# Starts-With Query

> Client language: PHP. Also available for [C#](https://docs.ravendb.net/6.2/client-api/session/querying/text-search/starts-with-query.md), [Python](https://docs.ravendb.net/6.2/client-api/session/querying/text-search/starts-with-query.python.md), [Node.js](https://docs.ravendb.net/6.2/client-api/session/querying/text-search/starts-with-query.nodejs.md).
>
> RavenDB publishes an official agent skill for coding assistants at https://docs.ravendb.net/skills/ravendb/SKILL.md (also installable with `npx skills add ravendb/skills`). The skill describes itself as: "Read this before writing any RavenDB query, client call or /databases/ request. Covers server setup, document modelling, the Node.js, .NET and Python clients, RQL, indexes, vector search and AI agents. Code written from recall tends to run and return the wrong rows, because RQL resembles SQL and the clients take field names as plain strings."

> **Note**
>
> - You can query for documents having a field that starts with some specified string.
>
> - Unless explicitly specified, the string comparisons are case-insensitive by default.
>
> - In this page:
>   - [StartsWith](#startswith)
>   - [StartsWith (case-sensitive)](#startswith-\(case-sensitive\))
>   - [Negate StartsWith](#negate-startswith)

## StartsWith

The results will contain only Product documents having a 'Name' field
that starts with any case variation of 'ch'.

### query

```php
/** @var array<Product> $products */
$products = $session
  ->query(Product::class)
  // Call 'StartsWith' on the field
  // Pass the prefix to search by
  ->whereStartsWith("Name", "Ch")
  ->toList();
```

### documentQuery

```php
/** @var array<Product> $products */
$products = $session->advanced()
  ->documentQuery(Product::class)
  // Call 'WhereStartsWith'
  // Pass the document field and the prefix to search by
  ->whereStartsWith("Name", "Ch")
  ->toList();
```

### RQL

```sql
from "Products"
where startsWith(Name, "Ch")
```

## StartsWith (case-sensitive)

The results will contain only Product documents having a 'Name' field
that starts with 'Ch'.

### query

```php
/** @var array<Product> $products */
$products = $session->advanced()
  ->query(Product::class)
  // Pass 'exact: true' to search for an EXACT prefix match
  ->whereStartsWith("Name", "Ch", true)
  ->toList();
```

### documentQuery

```php
/** @var array<Product> $products */
$products = $session->advanced()
  ->documentQuery(Product::class)
  // Call 'WhereStartsWith'
  // Pass 'exact: true' to search for an EXACT prefix match
  ->whereStartsWith("Name", "Ch", true)
  ->toList();
```

### RQL

```sql
from "Products"
where exact(startsWith(Name, "Ch"))
```

## Negate StartsWith

The results will contain only Product documents having a 'Name' field
that does NOT start with 'ch' or any other case variations of it.

### query

```php
/** @var array<Product> $products */
$products = $session
  ->query(Product::class)
  # Negate next statement
  ->not()
  // Call 'StartsWith' on the field
  // Pass the prefix to search by
  ->whereStartsWith("Name", "Ch")
  ->toList();
```

### documentQuery

```php
/** @var array<Product> $products */
$products = $session->advanced()
  ->documentQuery(Product::class)
  // Call 'Not' to negate the next predicate
  ->not()
  // Call 'WhereStartsWith'
  // Pass the document field and the prefix to search by
  ->whereStartsWith("Name", "Ch")
  ->toList();
```

### RQL

```sql
from "Products"
where (true and not startsWith(Name, "Ch"))
```

## See also

- [Query overview](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-query.php.md)
- [Ends-With query](https://docs.ravendb.net/6.2/client-api/session/querying/text-search/ends-with-query.php.md)
- [Full-text search](https://docs.ravendb.net/6.2/client-api/session/querying/text-search/full-text-search.php.md)
