# Labels & Properties

Source: https://docs.rushdb.com/2.x/learn/records-and-queries/labels-and-properties/

RushDB is schema-free — labels and properties emerge automatically as you write records. These APIs let you inspect, enumerate, and manage your schema at runtime.

---

## Labels

A **label** is a string tag applied to every record (e.g. `"Movie"`, `"User"`, `"Order"`). The labels API lets you discover which labels exist and how many records each has.

### Find Labels

**Python**

`db.labels.find()`

```python
# All labels and their record counts
result = db.labels.find({})
# → [LabelResult(name='MOVIE', count=3), LabelResult(name='ACTOR', count=3), ...]

# Labels that have records matching a condition
result = db.labels.find({"where": {"rating": {"$gte": 8}}})
# → [LabelResult(name='MOVIE', count=1)]
```

`db.labels.find()` accepts a standard [`where`](/learn/search-query/where-operators) clause. It returns all labels that have at least one record matching the condition.

**TypeScript**

`db.labels.find()`

```typescript
// All labels
const { data } = await db.labels.find()
// { MOVIE: 84, ACTOR: 312, DIRECTOR: 47 }

// Labels for records where rating > 8
const { data } = await db.labels.find({
  where: { rating: { $gt: 8 } }
})
// { MOVIE: 21 }
```

`find()` accepts the same `where`, `skip`, `limit` parameters as `db.records.find()`.

**Shell**

`POST /api/v1/labels/search`

```bash
# All labels
curl -X POST https://api.rushdb.com/api/v1/labels/search \
  -H "Authorization: Bearer $RUSHDB_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{}'

# Labels that have records matching a condition
curl -X POST https://api.rushdb.com/api/v1/labels/search \
  -H "Authorization: Bearer $RUSHDB_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"where": {"rating": {"$gte": 8}}}'
```

Response: `{ [label]: count }` map.

---

## Properties

A **property** is a field definition created automatically when you write a record with a new key. The properties API lets you inspect types, enumerate distinct values, and delete fields.

### Find Properties

**Python**

`db.properties.find()`

```python
# All properties
props = db.properties.find()

# Properties used by records matching a Record filter
props = db.properties.find({
    "labels": ["MOVIE"],
    "where": {"rating": {"$gte": 8}},
    "limit": 20
})
```

**TypeScript**

`db.properties.find()`

```typescript
const { data } = await db.properties.find({
  labels: ['MOVIE'],
  where: { rating: { $gte: 8 } }
})
// [{ id, name: 'rating', type: 'number', ... }, ...]
```

**Shell**

`POST /api/v1/properties/search`

```bash
curl -X POST https://api.rushdb.com/api/v1/properties/search \
  -H "Authorization: Bearer $RUSHDB_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"labels": ["MOVIE"], "where": {"rating": {"$gte": 8}}}'
```

### Find by ID

**Python**

`db.properties.find_by_id(property_id)`

```python
prop = db.properties.find_by_id("prop-123")
```

**TypeScript**

`db.properties.findById(id)`

```typescript
const prop = await db.properties.findById('property-id')
```

**Shell**

`GET /api/v1/properties/:propertyId`

```bash
curl https://api.rushdb.com/api/v1/properties/prop-123 \
  -H "Authorization: Bearer $RUSHDB_API_KEY"
```

### Get Property Values

Enumerate distinct values for a property — useful for building filter UIs, autocomplete, or feeding into `db.ai.get_schema()`.

**Python**

`db.properties.values(property_id, search_query?)`

```python
values_data = db.properties.values(
    property_id="prop-123",
    search_query={
        "query": "sci",    # filter values containing this text
        "orderBy": "asc",
        "limit": 100
    }
)

print(values_data.get("values"))  # list of distinct values
print(values_data.get("min"))     # numeric min (number/datetime props)
print(values_data.get("max"))     # numeric max (number/datetime props)
```

**TypeScript**

`db.properties.values(propertyId, params?)`

```typescript
const { data: genres } = await db.properties.values('prop-id-genre')
// ['sci-fi', 'action', 'drama', ...]

// With filter
const { data } = await db.properties.values('prop-id', {
  query: 'sci', // text prefix filter
  orderBy: 'asc',
  limit: 10
})
```

**Shell**

`POST /api/v1/properties/:propertyId/values`

```bash
curl -X POST https://api.rushdb.com/api/v1/properties/prop-123/values \
  -H "Authorization: Bearer $RUSHDB_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"query": "sci", "orderBy": "asc", "limit": 100}'
```

| Field     | Type              | Description                        |
| --------- | ----------------- | ---------------------------------- |
| `query`   | `string`          | Filter values containing this text |
| `orderBy` | `"asc" \| "desc"` | Sort direction                     |
| `skip`    | `number`          | Pagination offset                  |
| `limit`   | `number`          | Max values to return               |

### Delete Property

:::warning
Deletes the property definition and removes it from **all records** that have it. This is irreversible.
:::

**Python**

`db.properties.delete(property_id)`

```python
db.properties.delete("prop-123")
```

**TypeScript**

`db.properties.delete(id)`

```typescript
await db.properties.delete('property-id')
```

**Shell**

`DELETE /api/v1/properties/:propertyId`

```bash
curl -X DELETE https://api.rushdb.com/api/v1/properties/prop-123 \
  -H "Authorization: Bearer $RUSHDB_API_KEY"
```

---

## See also

- [Discover Your Schema](/learn/records-and-queries/discover-your-schema) — live schema via `db.ai.getSchema()`
- [Find & Query](/learn/records-and-queries/find-and-query) — query records by property value
- [Where Operators](/learn/search-query/where-operators) — filter syntax reference
