# Count

> Get the total number of records in a collection or matching a specific query using API Maker's g.sys.db.count method.

Source: https://docs.apimaker.dev/v4/examples/sys/db/count.html

> **The code in every language**
>
> Each example is the inside of `main`, written in every [language](https://docs.apimaker.dev/v4/docs/languages/index.html) API Maker runs : pick yours in the tabs, and every page shows it from then on. The types a call takes (`GetAll`, `DeepItem`…) are those of `am` : `from am import GetAll` in Python, `use am::GetAll;` in Rust, `import am.GetAll;` in Java and Kotlin ; PHP and C# have them without an import, Go names them `am.GetAll`.

`g.sys.db.count` calls the [count schema API](https://docs.apimaker.dev/v4/docs/apis-all/schema-apis/auto-generated-schema-based-count-api.html) of any table from your code, with the same headers and query parameters as over HTTP. It returns the data. The whole envelope (`success`, `statusCode`, `data`, `totalCount`, `errors`…) comes back when `true` is passed as the second argument in TypeScript, and through `full` in the other languages : `g.sys.db.full` (`g.Sys.Db.Full` in C# and Go, `$g->sys->db->full` in PHP).

## Simple get count

**TypeScript**

**Simple get count**

```typescript
let count = await g.sys.db.count({
    instance: "mysql_8", database: "inventory", collection: "customers",
});
```

**Python**

**Simple get count**

```python
count = await g.sys.db.count(
    'mysql_8', 'inventory', 'customers',
)
```

**PHP**

**Simple get count**

```php
$count = $g->sys->db->count(
    'mysql_8', 'inventory', 'customers',
);
```

**C#**

**Simple get count**

```csharp
var count = await g.Sys.Db.Count(new Count("mysql_8", "inventory", "customers"));
```

**Go**

**Simple get count**

```go
count, err := g.Sys.Db.Count(am.Count{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
})
if err != nil {
	return nil, err
}
```

**Rust**

**Simple get count**

```rust
let count = g.sys.db.count(Count::new("mysql_8", "inventory", "customers"))?;
```

**Java**

**Simple get count**

```java
var count = g.sys.db.count(new Count("mysql_8", "inventory", "customers"));
```

**Kotlin**

**Simple get count**

```kotlin
val count = g.sys.db.count(Count("mysql_8", "inventory", "customers"))
```

## get count [headers]

**TypeScript**

**get count with headers**

```typescript
let count = await g.sys.db.count({
    instance: "mysql_8", database: "inventory", collection: "customers",
    headers: {
        "x-am-response-case": "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
    },
});
```

**Python**

**get count with headers**

```python
count = await g.sys.db.count(
    'mysql_8', 'inventory', 'customers',
    headers={
        'x-am-response-case': 'capitalCase',  # noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
    },
)
```

**PHP**

**get count with headers**

```php
$count = $g->sys->db->count(
    'mysql_8', 'inventory', 'customers',
    headers: [
        'x-am-response-case' => 'capitalCase', // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
    ],
);
```

**C#**

**get count with headers**

```csharp
var count = await g.Sys.Db.Count(new Count("mysql_8", "inventory", "customers")
{
    Headers = new JsonObject
    {
        ["x-am-response-case"] = "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
    },
});
```

**Go**

**get count with headers**

```go
count, err := g.Sys.Db.Count(am.Count{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	Headers: am.M{
		"x-am-response-case": "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**get count with headers**

```rust
let count = g.sys.db.count(
    Count::new("mysql_8", "inventory", "customers")
        .headers(json!({
            "x-am-response-case": "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
        })),
)?;
```

**Java**

**get count with headers**

```java
var count = g.sys.db.count(new Count("mysql_8", "inventory", "customers")
    .headers(Map.of(
        "x-am-response-case", "capitalCase" // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
    )));
```

**Kotlin**

**get count with headers**

```kotlin
val count = g.sys.db.count(
    Count("mysql_8", "inventory", "customers")
        .headers(mapOf(
            "x-am-response-case" to "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
        )),
)
```

## get count [find]

**TypeScript**

**Simple find**

```typescript
let count = await g.sys.db.count({
    instance: "mysql_8", database: "inventory", collection: "customers",
    find:{
        "first_name": "Bob"
    }
});
```

**Python**

**Simple find**

```python
count = await g.sys.db.count(
    'mysql_8', 'inventory', 'customers',
    find={
        'first_name': 'Bob',
    },
)
```

**PHP**

**Simple find**

```php
$count = $g->sys->db->count(
    'mysql_8', 'inventory', 'customers',
    find: [
        'first_name' => 'Bob',
    ],
);
```

**C#**

**Simple find**

```csharp
var count = await g.Sys.Db.Count(new Count("mysql_8", "inventory", "customers")
{
    Find = new JsonObject
    {
        ["first_name"] = "Bob",
    },
});
```

**Go**

**Simple find**

```go
count, err := g.Sys.Db.Count(am.Count{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	Find: am.M{
		"first_name": "Bob",
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**Simple find**

```rust
let count = g.sys.db.count(
    Count::new("mysql_8", "inventory", "customers")
        .find(json!({
            "first_name": "Bob",
        })),
)?;
```

**Java**

**Simple find**

```java
var count = g.sys.db.count(new Count("mysql_8", "inventory", "customers")
    .find(Map.of(
        "first_name", "Bob"
    )));
```

**Kotlin**

**Simple find**

```kotlin
val count = g.sys.db.count(
    Count("mysql_8", "inventory", "customers")
        .find(mapOf(
            "first_name" to "Bob",
        )),
)
```

## $gt

**TypeScript**

**$gt**

```typescript
let count = await g.sys.db.count({
    instance: "mysql_8", database: "inventory", collection: "customers",
    find: {
        "customer_id": {
            "$gt": 4
        }
    }
});
```

**Python**

**$gt**

```python
count = await g.sys.db.count(
    'mysql_8', 'inventory', 'customers',
    find={
        'customer_id': {
            '$gt': 4,
        },
    },
)
```

**PHP**

**$gt**

```php
$count = $g->sys->db->count(
    'mysql_8', 'inventory', 'customers',
    find: [
        'customer_id' => [
            '$gt' => 4,
        ],
    ],
);
```

**C#**

**$gt**

```csharp
var count = await g.Sys.Db.Count(new Count("mysql_8", "inventory", "customers")
{
    Find = new JsonObject
    {
        ["customer_id"] = new JsonObject
        {
            ["$gt"] = 4,
        },
    },
});
```

**Go**

**$gt**

```go
count, err := g.Sys.Db.Count(am.Count{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	Find: am.M{
		"customer_id": am.M{
			"$gt": 4,
		},
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**$gt**

```rust
let count = g.sys.db.count(
    Count::new("mysql_8", "inventory", "customers")
        .find(json!({
            "customer_id": {
                "$gt": 4,
            },
        })),
)?;
```

**Java**

**$gt**

```java
var count = g.sys.db.count(new Count("mysql_8", "inventory", "customers")
    .find(Map.of(
        "customer_id", Map.of(
            "$gt", 4
        )
    )));
```

**Kotlin**

**$gt**

```kotlin
val count = g.sys.db.count(
    Count("mysql_8", "inventory", "customers")
        .find(mapOf(
            "customer_id" to mapOf(
                "\$gt" to 4,
            ),
        )),
)
```

## $gte

**TypeScript**

**$gte**

```typescript
let count = await g.sys.db.count({
    instance: "mysql_8", database: "inventory", collection: "customers",
    find: {
        "customer_id": {
            "$gte": 4
        }
    }
});
```

**Python**

**$gte**

```python
count = await g.sys.db.count(
    'mysql_8', 'inventory', 'customers',
    find={
        'customer_id': {
            '$gte': 4,
        },
    },
)
```

**PHP**

**$gte**

```php
$count = $g->sys->db->count(
    'mysql_8', 'inventory', 'customers',
    find: [
        'customer_id' => [
            '$gte' => 4,
        ],
    ],
);
```

**C#**

**$gte**

```csharp
var count = await g.Sys.Db.Count(new Count("mysql_8", "inventory", "customers")
{
    Find = new JsonObject
    {
        ["customer_id"] = new JsonObject
        {
            ["$gte"] = 4,
        },
    },
});
```

**Go**

**$gte**

```go
count, err := g.Sys.Db.Count(am.Count{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	Find: am.M{
		"customer_id": am.M{
			"$gte": 4,
		},
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**$gte**

```rust
let count = g.sys.db.count(
    Count::new("mysql_8", "inventory", "customers")
        .find(json!({
            "customer_id": {
                "$gte": 4,
            },
        })),
)?;
```

**Java**

**$gte**

```java
var count = g.sys.db.count(new Count("mysql_8", "inventory", "customers")
    .find(Map.of(
        "customer_id", Map.of(
            "$gte", 4
        )
    )));
```

**Kotlin**

**$gte**

```kotlin
val count = g.sys.db.count(
    Count("mysql_8", "inventory", "customers")
        .find(mapOf(
            "customer_id" to mapOf(
                "\$gte" to 4,
            ),
        )),
)
```

## $lt

**TypeScript**

**$lt**

```typescript
let count = await g.sys.db.count({
    instance: "mysql_8", database: "inventory", collection: "customers",
    find: {
        "customer_id": {
            "$lt": 4
        }
    }
});
```

**Python**

**$lt**

```python
count = await g.sys.db.count(
    'mysql_8', 'inventory', 'customers',
    find={
        'customer_id': {
            '$lt': 4,
        },
    },
)
```

**PHP**

**$lt**

```php
$count = $g->sys->db->count(
    'mysql_8', 'inventory', 'customers',
    find: [
        'customer_id' => [
            '$lt' => 4,
        ],
    ],
);
```

**C#**

**$lt**

```csharp
var count = await g.Sys.Db.Count(new Count("mysql_8", "inventory", "customers")
{
    Find = new JsonObject
    {
        ["customer_id"] = new JsonObject
        {
            ["$lt"] = 4,
        },
    },
});
```

**Go**

**$lt**

```go
count, err := g.Sys.Db.Count(am.Count{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	Find: am.M{
		"customer_id": am.M{
			"$lt": 4,
		},
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**$lt**

```rust
let count = g.sys.db.count(
    Count::new("mysql_8", "inventory", "customers")
        .find(json!({
            "customer_id": {
                "$lt": 4,
            },
        })),
)?;
```

**Java**

**$lt**

```java
var count = g.sys.db.count(new Count("mysql_8", "inventory", "customers")
    .find(Map.of(
        "customer_id", Map.of(
            "$lt", 4
        )
    )));
```

**Kotlin**

**$lt**

```kotlin
val count = g.sys.db.count(
    Count("mysql_8", "inventory", "customers")
        .find(mapOf(
            "customer_id" to mapOf(
                "\$lt" to 4,
            ),
        )),
)
```

## $lte

**TypeScript**

**$lte**

```typescript
let count = await g.sys.db.count({
    instance: "mysql_8", database: "inventory", collection: "customers",
    find: {
        "customer_id": {
            "$lte": 4
        }
    }
});
```

**Python**

**$lte**

```python
count = await g.sys.db.count(
    'mysql_8', 'inventory', 'customers',
    find={
        'customer_id': {
            '$lte': 4,
        },
    },
)
```

**PHP**

**$lte**

```php
$count = $g->sys->db->count(
    'mysql_8', 'inventory', 'customers',
    find: [
        'customer_id' => [
            '$lte' => 4,
        ],
    ],
);
```

**C#**

**$lte**

```csharp
var count = await g.Sys.Db.Count(new Count("mysql_8", "inventory", "customers")
{
    Find = new JsonObject
    {
        ["customer_id"] = new JsonObject
        {
            ["$lte"] = 4,
        },
    },
});
```

**Go**

**$lte**

```go
count, err := g.Sys.Db.Count(am.Count{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	Find: am.M{
		"customer_id": am.M{
			"$lte": 4,
		},
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**$lte**

```rust
let count = g.sys.db.count(
    Count::new("mysql_8", "inventory", "customers")
        .find(json!({
            "customer_id": {
                "$lte": 4,
            },
        })),
)?;
```

**Java**

**$lte**

```java
var count = g.sys.db.count(new Count("mysql_8", "inventory", "customers")
    .find(Map.of(
        "customer_id", Map.of(
            "$lte", 4
        )
    )));
```

**Kotlin**

**$lte**

```kotlin
val count = g.sys.db.count(
    Count("mysql_8", "inventory", "customers")
        .find(mapOf(
            "customer_id" to mapOf(
                "\$lte" to 4,
            ),
        )),
)
```

## $eq

**TypeScript**

**$eq**

```typescript
let count = await g.sys.db.count({
    instance: "mysql_8", database: "inventory", collection: "customers",
    find: {
        "first_name": {
            "$eq": "Bob"
        }
    }
});
```

**Python**

**$eq**

```python
count = await g.sys.db.count(
    'mysql_8', 'inventory', 'customers',
    find={
        'first_name': {
            '$eq': 'Bob',
        },
    },
)
```

**PHP**

**$eq**

```php
$count = $g->sys->db->count(
    'mysql_8', 'inventory', 'customers',
    find: [
        'first_name' => [
            '$eq' => 'Bob',
        ],
    ],
);
```

**C#**

**$eq**

```csharp
var count = await g.Sys.Db.Count(new Count("mysql_8", "inventory", "customers")
{
    Find = new JsonObject
    {
        ["first_name"] = new JsonObject
        {
            ["$eq"] = "Bob",
        },
    },
});
```

**Go**

**$eq**

```go
count, err := g.Sys.Db.Count(am.Count{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	Find: am.M{
		"first_name": am.M{
			"$eq": "Bob",
		},
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**$eq**

```rust
let count = g.sys.db.count(
    Count::new("mysql_8", "inventory", "customers")
        .find(json!({
            "first_name": {
                "$eq": "Bob",
            },
        })),
)?;
```

**Java**

**$eq**

```java
var count = g.sys.db.count(new Count("mysql_8", "inventory", "customers")
    .find(Map.of(
        "first_name", Map.of(
            "$eq", "Bob"
        )
    )));
```

**Kotlin**

**$eq**

```kotlin
val count = g.sys.db.count(
    Count("mysql_8", "inventory", "customers")
        .find(mapOf(
            "first_name" to mapOf(
                "\$eq" to "Bob",
            ),
        )),
)
```

## $ne

**TypeScript**

**$ne**

```typescript
let count = await g.sys.db.count({
    instance: "mysql_8", database: "inventory", collection: "customers",
    find: {
        "first_name": {
            "$ne": "Bob"
        }
    }
});
```

**Python**

**$ne**

```python
count = await g.sys.db.count(
    'mysql_8', 'inventory', 'customers',
    find={
        'first_name': {
            '$ne': 'Bob',
        },
    },
)
```

**PHP**

**$ne**

```php
$count = $g->sys->db->count(
    'mysql_8', 'inventory', 'customers',
    find: [
        'first_name' => [
            '$ne' => 'Bob',
        ],
    ],
);
```

**C#**

**$ne**

```csharp
var count = await g.Sys.Db.Count(new Count("mysql_8", "inventory", "customers")
{
    Find = new JsonObject
    {
        ["first_name"] = new JsonObject
        {
            ["$ne"] = "Bob",
        },
    },
});
```

**Go**

**$ne**

```go
count, err := g.Sys.Db.Count(am.Count{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	Find: am.M{
		"first_name": am.M{
			"$ne": "Bob",
		},
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**$ne**

```rust
let count = g.sys.db.count(
    Count::new("mysql_8", "inventory", "customers")
        .find(json!({
            "first_name": {
                "$ne": "Bob",
            },
        })),
)?;
```

**Java**

**$ne**

```java
var count = g.sys.db.count(new Count("mysql_8", "inventory", "customers")
    .find(Map.of(
        "first_name", Map.of(
            "$ne", "Bob"
        )
    )));
```

**Kotlin**

**$ne**

```kotlin
val count = g.sys.db.count(
    Count("mysql_8", "inventory", "customers")
        .find(mapOf(
            "first_name" to mapOf(
                "\$ne" to "Bob",
            ),
        )),
)
```

## $in

**TypeScript**

**$in**

```typescript
let count = await g.sys.db.count({
    instance: "mysql_8", database: "inventory", collection: "customers",
    find: {
        "customer_id": {
            "$in": [1, 2]
        }
    }
});
```

**Python**

**$in**

```python
count = await g.sys.db.count(
    'mysql_8', 'inventory', 'customers',
    find={
        'customer_id': {
            '$in': [1, 2],
        },
    },
)
```

**PHP**

**$in**

```php
$count = $g->sys->db->count(
    'mysql_8', 'inventory', 'customers',
    find: [
        'customer_id' => [
            '$in' => [1, 2],
        ],
    ],
);
```

**C#**

**$in**

```csharp
var count = await g.Sys.Db.Count(new Count("mysql_8", "inventory", "customers")
{
    Find = new JsonObject
    {
        ["customer_id"] = new JsonObject
        {
            ["$in"] = new JsonArray { 1, 2 },
        },
    },
});
```

**Go**

**$in**

```go
count, err := g.Sys.Db.Count(am.Count{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	Find: am.M{
		"customer_id": am.M{
			"$in": []any{1, 2},
		},
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**$in**

```rust
let count = g.sys.db.count(
    Count::new("mysql_8", "inventory", "customers")
        .find(json!({
            "customer_id": {
                "$in": [1, 2],
            },
        })),
)?;
```

**Java**

**$in**

```java
var count = g.sys.db.count(new Count("mysql_8", "inventory", "customers")
    .find(Map.of(
        "customer_id", Map.of(
            "$in", List.of(1, 2)
        )
    )));
```

**Kotlin**

**$in**

```kotlin
val count = g.sys.db.count(
    Count("mysql_8", "inventory", "customers")
        .find(mapOf(
            "customer_id" to mapOf(
                "\$in" to listOf(1, 2),
            ),
        )),
)
```

## $nin

**TypeScript**

**$nin**

```typescript
let count = await g.sys.db.count({
    instance: "mysql_8", database: "inventory", collection: "customers",
    find: {
        "customer_id": {
            "$nin": [1, 2]
        }
    }
});
```

**Python**

**$nin**

```python
count = await g.sys.db.count(
    'mysql_8', 'inventory', 'customers',
    find={
        'customer_id': {
            '$nin': [1, 2],
        },
    },
)
```

**PHP**

**$nin**

```php
$count = $g->sys->db->count(
    'mysql_8', 'inventory', 'customers',
    find: [
        'customer_id' => [
            '$nin' => [1, 2],
        ],
    ],
);
```

**C#**

**$nin**

```csharp
var count = await g.Sys.Db.Count(new Count("mysql_8", "inventory", "customers")
{
    Find = new JsonObject
    {
        ["customer_id"] = new JsonObject
        {
            ["$nin"] = new JsonArray { 1, 2 },
        },
    },
});
```

**Go**

**$nin**

```go
count, err := g.Sys.Db.Count(am.Count{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	Find: am.M{
		"customer_id": am.M{
			"$nin": []any{1, 2},
		},
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**$nin**

```rust
let count = g.sys.db.count(
    Count::new("mysql_8", "inventory", "customers")
        .find(json!({
            "customer_id": {
                "$nin": [1, 2],
            },
        })),
)?;
```

**Java**

**$nin**

```java
var count = g.sys.db.count(new Count("mysql_8", "inventory", "customers")
    .find(Map.of(
        "customer_id", Map.of(
            "$nin", List.of(1, 2)
        )
    )));
```

**Kotlin**

**$nin**

```kotlin
val count = g.sys.db.count(
    Count("mysql_8", "inventory", "customers")
        .find(mapOf(
            "customer_id" to mapOf(
                "\$nin" to listOf(1, 2),
            ),
        )),
)
```

## $and

**TypeScript**

**$and**

```typescript
let count = await g.sys.db.count({
    instance: "mysql_8", database: "inventory", collection: "customers",
    find: {
        "$and": [
            {
                "employee_Details.emp_Id": 1
            },
            {
                "city": "Baroda"
            }
        ]
    }
});
```

**Python**

**$and**

```python
count = await g.sys.db.count(
    'mysql_8', 'inventory', 'customers',
    find={
        '$and': [
            {
                'employee_Details.emp_Id': 1,
            },
            {
                'city': 'Baroda',
            },
        ],
    },
)
```

**PHP**

**$and**

```php
$count = $g->sys->db->count(
    'mysql_8', 'inventory', 'customers',
    find: [
        '$and' => [
            [
                'employee_Details.emp_Id' => 1,
            ],
            [
                'city' => 'Baroda',
            ],
        ],
    ],
);
```

**C#**

**$and**

```csharp
var count = await g.Sys.Db.Count(new Count("mysql_8", "inventory", "customers")
{
    Find = new JsonObject
    {
        ["$and"] = new JsonArray
        {
            new JsonObject
            {
                ["employee_Details.emp_Id"] = 1,
            },
            new JsonObject
            {
                ["city"] = "Baroda",
            },
        },
    },
});
```

**Go**

**$and**

```go
count, err := g.Sys.Db.Count(am.Count{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	Find: am.M{
		"$and": []any{
			am.M{
				"employee_Details.emp_Id": 1,
			},
			am.M{
				"city": "Baroda",
			},
		},
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**$and**

```rust
let count = g.sys.db.count(
    Count::new("mysql_8", "inventory", "customers")
        .find(json!({
            "$and": [
                {
                    "employee_Details.emp_Id": 1,
                },
                {
                    "city": "Baroda",
                },
            ],
        })),
)?;
```

**Java**

**$and**

```java
var count = g.sys.db.count(new Count("mysql_8", "inventory", "customers")
    .find(Map.of(
        "$and", List.of(
            Map.of(
                "employee_Details.emp_Id", 1
            ),
            Map.of(
                "city", "Baroda"
            )
        )
    )));
```

**Kotlin**

**$and**

```kotlin
val count = g.sys.db.count(
    Count("mysql_8", "inventory", "customers")
        .find(mapOf(
            "\$and" to listOf(
                mapOf(
                    "employee_Details.emp_Id" to 1,
                ),
                mapOf(
                    "city" to "Baroda",
                ),
            ),
        )),
)
```

## $or

**TypeScript**

**$or**

```typescript
let count = await g.sys.db.count({
    instance: "mysql_8", database: "inventory", collection: "customers",
    find: {
        "$or": [
            {
                "state": "Gujarat"
            },
            {
                "city": "Baroda"
            }
        ]
    }
});
```

**Python**

**$or**

```python
count = await g.sys.db.count(
    'mysql_8', 'inventory', 'customers',
    find={
        '$or': [
            {
                'state': 'Gujarat',
            },
            {
                'city': 'Baroda',
            },
        ],
    },
)
```

**PHP**

**$or**

```php
$count = $g->sys->db->count(
    'mysql_8', 'inventory', 'customers',
    find: [
        '$or' => [
            [
                'state' => 'Gujarat',
            ],
            [
                'city' => 'Baroda',
            ],
        ],
    ],
);
```

**C#**

**$or**

```csharp
var count = await g.Sys.Db.Count(new Count("mysql_8", "inventory", "customers")
{
    Find = new JsonObject
    {
        ["$or"] = new JsonArray
        {
            new JsonObject
            {
                ["state"] = "Gujarat",
            },
            new JsonObject
            {
                ["city"] = "Baroda",
            },
        },
    },
});
```

**Go**

**$or**

```go
count, err := g.Sys.Db.Count(am.Count{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	Find: am.M{
		"$or": []any{
			am.M{
				"state": "Gujarat",
			},
			am.M{
				"city": "Baroda",
			},
		},
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**$or**

```rust
let count = g.sys.db.count(
    Count::new("mysql_8", "inventory", "customers")
        .find(json!({
            "$or": [
                {
                    "state": "Gujarat",
                },
                {
                    "city": "Baroda",
                },
            ],
        })),
)?;
```

**Java**

**$or**

```java
var count = g.sys.db.count(new Count("mysql_8", "inventory", "customers")
    .find(Map.of(
        "$or", List.of(
            Map.of(
                "state", "Gujarat"
            ),
            Map.of(
                "city", "Baroda"
            )
        )
    )));
```

**Kotlin**

**$or**

```kotlin
val count = g.sys.db.count(
    Count("mysql_8", "inventory", "customers")
        .find(mapOf(
            "\$or" to listOf(
                mapOf(
                    "state" to "Gujarat",
                ),
                mapOf(
                    "city" to "Baroda",
                ),
            ),
        )),
)
```

## $like

**TypeScript**

**$like**

```typescript
let count = await g.sys.db.count({
    instance: "mysql_8", database: "inventory", collection: "customers",
    find: {
        "first_name": {
            "$like": "%Mall%"
        }
    }
});
```

**Python**

**$like**

```python
count = await g.sys.db.count(
    'mysql_8', 'inventory', 'customers',
    find={
        'first_name': {
            '$like': '%Mall%',
        },
    },
)
```

**PHP**

**$like**

```php
$count = $g->sys->db->count(
    'mysql_8', 'inventory', 'customers',
    find: [
        'first_name' => [
            '$like' => '%Mall%',
        ],
    ],
);
```

**C#**

**$like**

```csharp
var count = await g.Sys.Db.Count(new Count("mysql_8", "inventory", "customers")
{
    Find = new JsonObject
    {
        ["first_name"] = new JsonObject
        {
            ["$like"] = "%Mall%",
        },
    },
});
```

**Go**

**$like**

```go
count, err := g.Sys.Db.Count(am.Count{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	Find: am.M{
		"first_name": am.M{
			"$like": "%Mall%",
		},
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**$like**

```rust
let count = g.sys.db.count(
    Count::new("mysql_8", "inventory", "customers")
        .find(json!({
            "first_name": {
                "$like": "%Mall%",
            },
        })),
)?;
```

**Java**

**$like**

```java
var count = g.sys.db.count(new Count("mysql_8", "inventory", "customers")
    .find(Map.of(
        "first_name", Map.of(
            "$like", "%Mall%"
        )
    )));
```

**Kotlin**

**$like**

```kotlin
val count = g.sys.db.count(
    Count("mysql_8", "inventory", "customers")
        .find(mapOf(
            "first_name" to mapOf(
                "\$like" to "%Mall%",
            ),
        )),
)
```

## floating value support

**TypeScript**

**floating value support**

```typescript
let count = await g.sys.db.count({
    instance: "mysql_8", database: "inventory", collection: "customers",
    find: {
        "customer_id":{
            "$gt": 2.2
        }
    }
});
```

**Python**

**floating value support**

```python
count = await g.sys.db.count(
    'mysql_8', 'inventory', 'customers',
    find={
        'customer_id': {
            '$gt': 2.2,
        },
    },
)
```

**PHP**

**floating value support**

```php
$count = $g->sys->db->count(
    'mysql_8', 'inventory', 'customers',
    find: [
        'customer_id' => [
            '$gt' => 2.2,
        ],
    ],
);
```

**C#**

**floating value support**

```csharp
var count = await g.Sys.Db.Count(new Count("mysql_8", "inventory", "customers")
{
    Find = new JsonObject
    {
        ["customer_id"] = new JsonObject
        {
            ["$gt"] = 2.2,
        },
    },
});
```

**Go**

**floating value support**

```go
count, err := g.Sys.Db.Count(am.Count{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	Find: am.M{
		"customer_id": am.M{
			"$gt": 2.2,
		},
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**floating value support**

```rust
let count = g.sys.db.count(
    Count::new("mysql_8", "inventory", "customers")
        .find(json!({
            "customer_id": {
                "$gt": 2.2,
            },
        })),
)?;
```

**Java**

**floating value support**

```java
var count = g.sys.db.count(new Count("mysql_8", "inventory", "customers")
    .find(Map.of(
        "customer_id", Map.of(
            "$gt", 2.2
        )
    )));
```

**Kotlin**

**floating value support**

```kotlin
val count = g.sys.db.count(
    Count("mysql_8", "inventory", "customers")
        .find(mapOf(
            "customer_id" to mapOf(
                "\$gt" to 2.2,
            ),
        )),
)
```

## Structure

**TypeScript**

**Count method**

```typescript
let count = await g.sys.db.count({
    instance: "INSTANCE_NAME", database: 'DB_NAME', collection: "COLLECTION_NAME",
    find: {
        "COLUMN_NAME": "VALUE",
    },
    headers: {
        "x-am-response-case": "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
        "x-am-response-object-type": "make_flat", // no_action | make_flat
        "x-am-meta": "true", // true, false
        "x-am-internationalization": "USER_I18N_ID",
        "x-am-run-in-sandbox": "2",
        "x-am-content-type-response": "text/xml", // application/json | text/xml | text/yaml | text/plain | text/html | application/octet-stream
        "x-am-cache-control": "reset_cache", // no_action | reset_cache
        "x-am-get-encrypted-data": "get_only_encryption", // no_encryption | get_only_encryption | get_data_and_encryption
        "x-am-sandbox-timeout": "13000",
        "x-no-compression": "true", // true | false
        "x-am-encrypted-payload": "true", // user will send 'true', when payload is encrypted for transfer
        // Multi-tenant : the tenant of the request, each instance finds it in its own tenants table
        "x-am-tenant-username": "TENANT_USERNAME", // ex: acme
        // Authorization headers
        "x-am-authorization": "AUTHORIZATION_TOKEN",
        "x-am-user-authorization": "API_USER_TOKEN",
        "x-aws-authorization": "AWS_TOKEN",
        "x-google-authorization": "GOOGLE_TOKEN",
        "x-azure-authorization": "AZURE_TOKEN",
    },
});
```

**Python**

**Count method**

```python
count = await g.sys.db.count(
    'INSTANCE_NAME', 'DB_NAME', 'COLLECTION_NAME',
    find={
        'COLUMN_NAME': 'VALUE',
    },
    headers={
        'x-am-response-case': 'capitalCase',  # noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
        'x-am-response-object-type': 'make_flat',  # no_action | make_flat
        'x-am-meta': 'true',  # true, false
        'x-am-internationalization': 'USER_I18N_ID',
        'x-am-run-in-sandbox': '2',
        'x-am-content-type-response': 'text/xml',  # application/json | text/xml | text/yaml | text/plain | text/html | application/octet-stream
        'x-am-cache-control': 'reset_cache',  # no_action | reset_cache
        'x-am-get-encrypted-data': 'get_only_encryption',  # no_encryption | get_only_encryption | get_data_and_encryption
        'x-am-sandbox-timeout': '13000',
        'x-no-compression': 'true',  # true | false
        'x-am-encrypted-payload': 'true',  # user will send 'true', when payload is encrypted for transfer
        # Multi-tenant : the tenant of the request, each instance finds it in its own tenants table
        'x-am-tenant-username': 'TENANT_USERNAME',  # ex: acme
        # Authorization headers
        'x-am-authorization': 'AUTHORIZATION_TOKEN',
        'x-am-user-authorization': 'API_USER_TOKEN',
        'x-aws-authorization': 'AWS_TOKEN',
        'x-google-authorization': 'GOOGLE_TOKEN',
        'x-azure-authorization': 'AZURE_TOKEN',
    },
)
```

**PHP**

**Count method**

```php
$count = $g->sys->db->count(
    'INSTANCE_NAME', 'DB_NAME', 'COLLECTION_NAME',
    find: [
        'COLUMN_NAME' => 'VALUE',
    ],
    headers: [
        'x-am-response-case' => 'capitalCase', // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
        'x-am-response-object-type' => 'make_flat', // no_action | make_flat
        'x-am-meta' => 'true', // true, false
        'x-am-internationalization' => 'USER_I18N_ID',
        'x-am-run-in-sandbox' => '2',
        'x-am-content-type-response' => 'text/xml', // application/json | text/xml | text/yaml | text/plain | text/html | application/octet-stream
        'x-am-cache-control' => 'reset_cache', // no_action | reset_cache
        'x-am-get-encrypted-data' => 'get_only_encryption', // no_encryption | get_only_encryption | get_data_and_encryption
        'x-am-sandbox-timeout' => '13000',
        'x-no-compression' => 'true', // true | false
        'x-am-encrypted-payload' => 'true', // user will send 'true', when payload is encrypted for transfer
        // Multi-tenant : the tenant of the request, each instance finds it in its own tenants table
        'x-am-tenant-username' => 'TENANT_USERNAME', // ex: acme
        // Authorization headers
        'x-am-authorization' => 'AUTHORIZATION_TOKEN',
        'x-am-user-authorization' => 'API_USER_TOKEN',
        'x-aws-authorization' => 'AWS_TOKEN',
        'x-google-authorization' => 'GOOGLE_TOKEN',
        'x-azure-authorization' => 'AZURE_TOKEN',
    ],
);
```

**C#**

**Count method**

```csharp
var count = await g.Sys.Db.Count(new Count("INSTANCE_NAME", "DB_NAME", "COLLECTION_NAME")
{
    Find = new JsonObject
    {
        ["COLUMN_NAME"] = "VALUE",
    },
    Headers = new JsonObject
    {
        ["x-am-response-case"] = "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
        ["x-am-response-object-type"] = "make_flat", // no_action | make_flat
        ["x-am-meta"] = "true", // true, false
        ["x-am-internationalization"] = "USER_I18N_ID",
        ["x-am-run-in-sandbox"] = "2",
        ["x-am-content-type-response"] = "text/xml", // application/json | text/xml | text/yaml | text/plain | text/html | application/octet-stream
        ["x-am-cache-control"] = "reset_cache", // no_action | reset_cache
        ["x-am-get-encrypted-data"] = "get_only_encryption", // no_encryption | get_only_encryption | get_data_and_encryption
        ["x-am-sandbox-timeout"] = "13000",
        ["x-no-compression"] = "true", // true | false
        ["x-am-encrypted-payload"] = "true", // user will send 'true', when payload is encrypted for transfer
        // Multi-tenant : the tenant of the request, each instance finds it in its own tenants table
        ["x-am-tenant-username"] = "TENANT_USERNAME", // ex: acme
        // Authorization headers
        ["x-am-authorization"] = "AUTHORIZATION_TOKEN",
        ["x-am-user-authorization"] = "API_USER_TOKEN",
        ["x-aws-authorization"] = "AWS_TOKEN",
        ["x-google-authorization"] = "GOOGLE_TOKEN",
        ["x-azure-authorization"] = "AZURE_TOKEN",
    },
});
```

**Go**

**Count method**

```go
count, err := g.Sys.Db.Count(am.Count{
	Instance: "INSTANCE_NAME", Database: "DB_NAME", Collection: "COLLECTION_NAME",
	Find: am.M{
		"COLUMN_NAME": "VALUE",
	},
	Headers: am.M{
		"x-am-response-case":         "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
		"x-am-response-object-type":  "make_flat",   // no_action | make_flat
		"x-am-meta":                  "true",        // true, false
		"x-am-internationalization":  "USER_I18N_ID",
		"x-am-run-in-sandbox":        "2",
		"x-am-content-type-response": "text/xml",            // application/json | text/xml | text/yaml | text/plain | text/html | application/octet-stream
		"x-am-cache-control":         "reset_cache",         // no_action | reset_cache
		"x-am-get-encrypted-data":    "get_only_encryption", // no_encryption | get_only_encryption | get_data_and_encryption
		"x-am-sandbox-timeout":       "13000",
		"x-no-compression":           "true", // true | false
		"x-am-encrypted-payload":     "true", // user will send 'true', when payload is encrypted for transfer
		// Multi-tenant : the tenant of the request, each instance finds it in its own tenants table
		"x-am-tenant-username": "TENANT_USERNAME", // ex: acme
		// Authorization headers
		"x-am-authorization":      "AUTHORIZATION_TOKEN",
		"x-am-user-authorization": "API_USER_TOKEN",
		"x-aws-authorization":     "AWS_TOKEN",
		"x-google-authorization":  "GOOGLE_TOKEN",
		"x-azure-authorization":   "AZURE_TOKEN",
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**Count method**

```rust
let count = g.sys.db.count(
    Count::new("INSTANCE_NAME", "DB_NAME", "COLLECTION_NAME")
        .find(json!({
            "COLUMN_NAME": "VALUE",
        }))
        .headers(json!({
            "x-am-response-case": "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
            "x-am-response-object-type": "make_flat", // no_action | make_flat
            "x-am-meta": "true", // true, false
            "x-am-internationalization": "USER_I18N_ID",
            "x-am-run-in-sandbox": "2",
            "x-am-content-type-response": "text/xml", // application/json | text/xml | text/yaml | text/plain | text/html | application/octet-stream
            "x-am-cache-control": "reset_cache", // no_action | reset_cache
            "x-am-get-encrypted-data": "get_only_encryption", // no_encryption | get_only_encryption | get_data_and_encryption
            "x-am-sandbox-timeout": "13000",
            "x-no-compression": "true", // true | false
            "x-am-encrypted-payload": "true", // user will send 'true', when payload is encrypted for transfer
            // Multi-tenant : the tenant of the request, each instance finds it in its own tenants table
            "x-am-tenant-username": "TENANT_USERNAME", // ex: acme
            // Authorization headers
            "x-am-authorization": "AUTHORIZATION_TOKEN",
            "x-am-user-authorization": "API_USER_TOKEN",
            "x-aws-authorization": "AWS_TOKEN",
            "x-google-authorization": "GOOGLE_TOKEN",
            "x-azure-authorization": "AZURE_TOKEN",
        })),
)?;
```

**Java**

**Count method**

```java
var count = g.sys.db.count(new Count("INSTANCE_NAME", "DB_NAME", "COLLECTION_NAME")
    .find(Map.of(
        "COLUMN_NAME", "VALUE"
    ))
    .headers(JsonObject.of(
        "x-am-response-case", "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
        "x-am-response-object-type", "make_flat", // no_action | make_flat
        "x-am-meta", "true", // true, false
        "x-am-internationalization", "USER_I18N_ID",
        "x-am-run-in-sandbox", "2",
        "x-am-content-type-response", "text/xml", // application/json | text/xml | text/yaml | text/plain | text/html | application/octet-stream
        "x-am-cache-control", "reset_cache", // no_action | reset_cache
        "x-am-get-encrypted-data", "get_only_encryption", // no_encryption | get_only_encryption | get_data_and_encryption
        "x-am-sandbox-timeout", "13000",
        "x-no-compression", "true", // true | false
        "x-am-encrypted-payload", "true", // user will send 'true', when payload is encrypted for transfer
        // Multi-tenant : the tenant of the request, each instance finds it in its own tenants table
        "x-am-tenant-username", "TENANT_USERNAME", // ex: acme
        // Authorization headers
        "x-am-authorization", "AUTHORIZATION_TOKEN",
        "x-am-user-authorization", "API_USER_TOKEN",
        "x-aws-authorization", "AWS_TOKEN",
        "x-google-authorization", "GOOGLE_TOKEN",
        "x-azure-authorization", "AZURE_TOKEN"
    )));
```

**Kotlin**

**Count method**

```kotlin
val count = g.sys.db.count(
    Count("INSTANCE_NAME", "DB_NAME", "COLLECTION_NAME")
        .find(mapOf(
            "COLUMN_NAME" to "VALUE",
        ))
        .headers(mapOf(
            "x-am-response-case" to "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
            "x-am-response-object-type" to "make_flat", // no_action | make_flat
            "x-am-meta" to "true", // true, false
            "x-am-internationalization" to "USER_I18N_ID",
            "x-am-run-in-sandbox" to "2",
            "x-am-content-type-response" to "text/xml", // application/json | text/xml | text/yaml | text/plain | text/html | application/octet-stream
            "x-am-cache-control" to "reset_cache", // no_action | reset_cache
            "x-am-get-encrypted-data" to "get_only_encryption", // no_encryption | get_only_encryption | get_data_and_encryption
            "x-am-sandbox-timeout" to "13000",
            "x-no-compression" to "true", // true | false
            "x-am-encrypted-payload" to "true", // user will send 'true', when payload is encrypted for transfer
            // Multi-tenant : the tenant of the request, each instance finds it in its own tenants table
            "x-am-tenant-username" to "TENANT_USERNAME", // ex: acme
            // Authorization headers
            "x-am-authorization" to "AUTHORIZATION_TOKEN",
            "x-am-user-authorization" to "API_USER_TOKEN",
            "x-aws-authorization" to "AWS_TOKEN",
            "x-google-authorization" to "GOOGLE_TOKEN",
            "x-azure-authorization" to "AZURE_TOKEN",
        )),
)
```

## Multi-tenant
- `instance: "crm::acme"` works on the database of the tenant `acme` of the [multi-tenant](https://docs.apimaker.dev/v4/docs/features/multi-tenant.html) instance `crm`.
- With `instance: "crm"`, the call works on the database of the tenant of the request: a custom API called with the [x-am-tenant-username](https://docs.apimaker.dev/v4/docs/apis-all/header/requestHeader.html#x-am-tenant-username) header passes it on to the APIs it calls. A request without a tenant works on the structure database.

**TypeScript**

**Count the customers of the tenant acme**

```typescript
let count = await g.sys.db.count({
    instance: "crm::acme", database: "crm", collection: "customers",
    find: {
        "first_name": "Bob"
    }
});
```

**Python**

**Count the customers of the tenant acme**

```python
count = await g.sys.db.count(
    'crm::acme', 'crm', 'customers',
    find={
        'first_name': 'Bob',
    },
)
```

**PHP**

**Count the customers of the tenant acme**

```php
$count = $g->sys->db->count(
    'crm::acme', 'crm', 'customers',
    find: [
        'first_name' => 'Bob',
    ],
);
```

**C#**

**Count the customers of the tenant acme**

```csharp
var count = await g.Sys.Db.Count(new Count("crm::acme", "crm", "customers")
{
    Find = new JsonObject
    {
        ["first_name"] = "Bob",
    },
});
```

**Go**

**Count the customers of the tenant acme**

```go
count, err := g.Sys.Db.Count(am.Count{
	Instance: "crm::acme", Database: "crm", Collection: "customers",
	Find: am.M{
		"first_name": "Bob",
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**Count the customers of the tenant acme**

```rust
let count = g.sys.db.count(
    Count::new("crm::acme", "crm", "customers")
        .find(json!({
            "first_name": "Bob",
        })),
)?;
```

**Java**

**Count the customers of the tenant acme**

```java
var count = g.sys.db.count(new Count("crm::acme", "crm", "customers")
    .find(Map.of(
        "first_name", "Bob"
    )));
```

**Kotlin**

**Count the customers of the tenant acme**

```kotlin
val count = g.sys.db.count(
    Count("crm::acme", "crm", "customers")
        .find(mapOf(
            "first_name" to "Bob",
        )),
)
```

## Without a schema

`g.sys.db.gen.countGen` takes the same arguments and calls the [count generated API](https://docs.apimaker.dev/v4/docs/apis-all/schema-apis/auto-generated-schema-based-count-api.html#without-a-schema) : no schema, so the data is read and written as it is in the table, without the conversions, validations and defaults of the schema.

| Language | The call |
|---|---|
| TypeScript | `g.sys.db.gen.countGen(…)` |
| Python | `g.sys.db.gen.count_gen(…)` |
| PHP | `$g->sys->db->gen->countGen(…)` |
| C#, Go | `g.Sys.Db.Gen.CountGen(…)` |
| Rust | `g.sys.db.count_gen(Count::new(…))` |
| Java, Kotlin | `g.sys.db.gen.countGen(…)` |

## Related

- [Count API](https://docs.apimaker.dev/v4/docs/apis-all/schema-apis/auto-generated-schema-based-count-api.html) · [Generated API from code](https://docs.apimaker.dev/v4/examples/sys/db/count.html#without-a-schema) · [The global object g](https://docs.apimaker.dev/v4/docs/pre-defined-terms/global-object-g.html)
