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

# Starts-With Query

> Client language: Node.js. 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), [PHP](https://docs.ravendb.net/6.2/client-api/session/querying/text-search/starts-with-query.php.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**
>
> - Use `whereStartsWith` to 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:
>   - [whereStartsWith](#wherestartswith)
>   - [whereStartsWith (case-sensitive)](#wherestartswith-\(case-sensitive\))
>   - [Negate whereStartsWith](#negate-wherestartswith)
>   - [Syntax](#syntax)

## whereStartsWith

### Query

```javascript
const products = await session
  .query({ collection: "Products" })
   // Call 'whereStartsWith'
   // Pass the document field and the prefix to search by
  .whereStartsWith("Name", "Ch")
  .all();

// Results will contain only Product documents having a 'Name' field
// that starts with any case variation of 'ch'
```

### RQL

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

## whereStartsWith (case-sensitive)

### Query

```javascript
const products = await session
  .query({ collection: "Products" })
  // Call 'whereStartsWith'
  // Pass 'true' as the 3'rd parameter to search for an EXACT prefix match
  .whereStartsWith("Name", "Ch", true)
  .all();

// Results will contain only Product documents having a 'Name' field
// that starts with 'Ch'
```

### RQL

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

## Negate whereStartsWith

### Query

```javascript
const products = await session
  .query({ collection: "Products" })
  // Call 'Not' to negate the next predicate
  .not()
  // Call 'whereStartsWith'
  // Pass the document field and the prefix to search by
  .whereStartsWith("Name", "Ch")
  .all();

// Results will contain only Product documents having a 'Name' field
// that does NOT start with 'ch' or any other case variations of it
```

### RQL

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

## Syntax

```javascript
// Available overloads:
whereStartsWith(fieldName, value);
whereStartsWith(fieldName, value, exact);
```

| Parameter | Type | Description |
| - | - | - |
| **fieldName** | string | The field name in which to search |
| **value** | string | The **prefix** string to search by |
| **exact** | boolean | `false` - search is case-insensitive<br />`true` - search is case-sensitive |

## See also

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