Indexes

Without an index, a query reads every document of the collection. That is fast for thousands of documents. For millions, or to get documents in order, or to make sure a value never repeats, create an index on the field you search by.

The examples use the customers collection and the environment variables of Getting started.

Which index do I need?

Type Use it to Unique values Query it with
map Find a document by an exact value: an email, a username, an external id. Yes, always value
btree Ranges and order: dates, amounts, scores. Values can repeat. Optional (unique) from, to, reverse
fts Find documents by the words of a text: names, titles, descriptions. No match

Indexes are kept in memory and updated on every write. map indexes, and btree indexes with unique, are checked before each write, so a repeated value is rejected.

Look up by email (map)

Create the index:

curl -X POST "https://inceptiondb.hola.cloud/v1/databases/$INCEPTIONDB_DATABASE/collections/customers:createIndex" \
  -H "Api-Key: $INCEPTIONDB_API_KEY" \
  -H "Api-Secret: $INCEPTIONDB_API_SECRET" \
  -d '{"name": "by_email", "type": "map", "field": "email"}'
POST /v1/databases/$INCEPTIONDB_DATABASE/collections/customers:createIndex HTTP/1.1
Host: inceptiondb.hola.cloud
Api-Key: $INCEPTIONDB_API_KEY
Api-Secret: $INCEPTIONDB_API_SECRET

{"name": "by_email", "type": "map", "field": "email"}
package main

import (
	"fmt"
	"io"
	"net/http"
	"os"
	"encoding/json"
	"strings"
)

func main() {
	payload := map[string]any{"field": "email", "name": "by_email", "type": "map"}
	bodyBytes, err := json.Marshal(payload)
	if err != nil {
		panic(err)
	}
	body := string(bodyBytes)

	req, err := http.NewRequest("POST", "https://inceptiondb.hola.cloud/v1/databases/" + os.Getenv("INCEPTIONDB_DATABASE") + "/collections/customers:createIndex", strings.NewReader(body))
	if err != nil {
		panic(err)
	}
	req.Header.Set("Api-Key", os.Getenv("INCEPTIONDB_API_KEY"))
	req.Header.Set("Api-Secret", os.Getenv("INCEPTIONDB_API_SECRET"))

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	responseBody, err := io.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(responseBody))
}
<?php
$payload = ['field' => 'email', 'name' => 'by_email', 'type' => 'map'];
$body = json_encode($payload);

$ch = curl_init();

curl_setopt_array($ch, [
    CURLOPT_URL => 'https://inceptiondb.hola.cloud/v1/databases/' . getenv('INCEPTIONDB_DATABASE') . '/collections/customers:createIndex',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS => $body,
    CURLOPT_HTTPHEADER => [
        'Api-Key: ' . getenv('INCEPTIONDB_API_KEY'),
        'Api-Secret: ' . getenv('INCEPTIONDB_API_SECRET'),
    ],
]);

$response = curl_exec($ch);
if ($response === false) {
    throw new Exception(curl_error($ch));
}
curl_close($ch);

echo $response;
import os
import requests

import json

headers = {
    "Api-Key": os.environ["INCEPTIONDB_API_KEY"],
    "Api-Secret": os.environ["INCEPTIONDB_API_SECRET"],
}

payload = {"field": "email", "name": "by_email", "type": "map"}
body = json.dumps(payload)

response = requests.request(
    "POST",
    "https://inceptiondb.hola.cloud/v1/databases/" + os.environ["INCEPTIONDB_DATABASE"] + "/collections/customers:createIndex",
    headers=headers,
    data=body
)

print(response.text)
const payload = {"field": "email", "name": "by_email", "type": "map"};

const response = await fetch("https://inceptiondb.hola.cloud/v1/databases/" + process.env.INCEPTIONDB_DATABASE + "/collections/customers:createIndex", {
  method: "POST",
  headers: {
    "Api-Key": process.env.INCEPTIONDB_API_KEY,
    "Api-Secret": process.env.INCEPTIONDB_API_SECRET
  },
  body: JSON.stringify(payload)
});

console.log(await response.text());
// Fill in your values. Never put an API secret in code that runs in a public web page.
const INCEPTIONDB_DATABASE = "your-inceptiondb-database";
const INCEPTIONDB_API_KEY = "your-inceptiondb-api-key";
const INCEPTIONDB_API_SECRET = "your-inceptiondb-api-secret";

const payload = {"field": "email", "name": "by_email", "type": "map"};

const response = await fetch("https://inceptiondb.hola.cloud/v1/databases/" + INCEPTIONDB_DATABASE + "/collections/customers:createIndex", {
  method: "POST",
  headers: {
    "Api-Key": INCEPTIONDB_API_KEY,
    "Api-Secret": INCEPTIONDB_API_SECRET
  },
  body: JSON.stringify(payload)
});

const text = await response.text();
console.log(text);
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Map;
import java.util.List;

public class Main {
    public static void main(String[] args) throws Exception {
        var payload = Map.of("field", "email", "name", "by_email", "type", "map");
        var body = new ObjectMapper().writeValueAsString(payload);

        var request = HttpRequest.newBuilder()
            .uri(URI.create("https://inceptiondb.hola.cloud/v1/databases/" + System.getenv("INCEPTIONDB_DATABASE") + "/collections/customers:createIndex"))
            .method("POST", HttpRequest.BodyPublishers.ofString(body))
            .header("Api-Key", System.getenv("INCEPTIONDB_API_KEY"))
            .header("Api-Secret", System.getenv("INCEPTIONDB_API_SECRET"))
            .build();

        var response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}
1{"field":"email","name":"by_email","sparse":false,"type":"map"}

Find a customer by email:

curl -X POST "https://inceptiondb.hola.cloud/v1/databases/$INCEPTIONDB_DATABASE/collections/customers:find" \
  -H "Api-Key: $INCEPTIONDB_API_KEY" \
  -H "Api-Secret: $INCEPTIONDB_API_SECRET" \
  -d '{"index": "by_email", "value": "grace@example.com"}'
POST /v1/databases/$INCEPTIONDB_DATABASE/collections/customers:find HTTP/1.1
Host: inceptiondb.hola.cloud
Api-Key: $INCEPTIONDB_API_KEY
Api-Secret: $INCEPTIONDB_API_SECRET

{"index": "by_email", "value": "grace@example.com"}
package main

import (
	"fmt"
	"io"
	"net/http"
	"os"
	"encoding/json"
	"strings"
)

func main() {
	payload := map[string]any{"index": "by_email", "value": "grace@example.com"}
	bodyBytes, err := json.Marshal(payload)
	if err != nil {
		panic(err)
	}
	body := string(bodyBytes)

	req, err := http.NewRequest("POST", "https://inceptiondb.hola.cloud/v1/databases/" + os.Getenv("INCEPTIONDB_DATABASE") + "/collections/customers:find", strings.NewReader(body))
	if err != nil {
		panic(err)
	}
	req.Header.Set("Api-Key", os.Getenv("INCEPTIONDB_API_KEY"))
	req.Header.Set("Api-Secret", os.Getenv("INCEPTIONDB_API_SECRET"))

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	responseBody, err := io.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(responseBody))
}
<?php
$payload = ['index' => 'by_email', 'value' => 'grace@example.com'];
$body = json_encode($payload);

$ch = curl_init();

curl_setopt_array($ch, [
    CURLOPT_URL => 'https://inceptiondb.hola.cloud/v1/databases/' . getenv('INCEPTIONDB_DATABASE') . '/collections/customers:find',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS => $body,
    CURLOPT_HTTPHEADER => [
        'Api-Key: ' . getenv('INCEPTIONDB_API_KEY'),
        'Api-Secret: ' . getenv('INCEPTIONDB_API_SECRET'),
    ],
]);

$response = curl_exec($ch);
if ($response === false) {
    throw new Exception(curl_error($ch));
}
curl_close($ch);

echo $response;
import os
import requests

import json

headers = {
    "Api-Key": os.environ["INCEPTIONDB_API_KEY"],
    "Api-Secret": os.environ["INCEPTIONDB_API_SECRET"],
}

payload = {"index": "by_email", "value": "grace@example.com"}
body = json.dumps(payload)

response = requests.request(
    "POST",
    "https://inceptiondb.hola.cloud/v1/databases/" + os.environ["INCEPTIONDB_DATABASE"] + "/collections/customers:find",
    headers=headers,
    data=body
)

print(response.text)
const payload = {"index": "by_email", "value": "grace@example.com"};

const response = await fetch("https://inceptiondb.hola.cloud/v1/databases/" + process.env.INCEPTIONDB_DATABASE + "/collections/customers:find", {
  method: "POST",
  headers: {
    "Api-Key": process.env.INCEPTIONDB_API_KEY,
    "Api-Secret": process.env.INCEPTIONDB_API_SECRET
  },
  body: JSON.stringify(payload)
});

console.log(await response.text());
// Fill in your values. Never put an API secret in code that runs in a public web page.
const INCEPTIONDB_DATABASE = "your-inceptiondb-database";
const INCEPTIONDB_API_KEY = "your-inceptiondb-api-key";
const INCEPTIONDB_API_SECRET = "your-inceptiondb-api-secret";

const payload = {"index": "by_email", "value": "grace@example.com"};

const response = await fetch("https://inceptiondb.hola.cloud/v1/databases/" + INCEPTIONDB_DATABASE + "/collections/customers:find", {
  method: "POST",
  headers: {
    "Api-Key": INCEPTIONDB_API_KEY,
    "Api-Secret": INCEPTIONDB_API_SECRET
  },
  body: JSON.stringify(payload)
});

const text = await response.text();
console.log(text);
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Map;
import java.util.List;

public class Main {
    public static void main(String[] args) throws Exception {
        var payload = Map.of("index", "by_email", "value", "grace@example.com");
        var body = new ObjectMapper().writeValueAsString(payload);

        var request = HttpRequest.newBuilder()
            .uri(URI.create("https://inceptiondb.hola.cloud/v1/databases/" + System.getenv("INCEPTIONDB_DATABASE") + "/collections/customers:find"))
            .method("POST", HttpRequest.BodyPublishers.ofString(body))
            .header("Api-Key", System.getenv("INCEPTIONDB_API_KEY"))
            .header("Api-Secret", System.getenv("INCEPTIONDB_API_SECRET"))
            .build();

        var response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}
1{"id":"grace","name":"Grace Hopper","email":"grace@example.com","plan":"team","country":"US","mrr":480,"tags":["vip"],"address":{"city":"New York","zip":"10001"}}

From now on, inserting another customer with an existing email fails with 409 Conflict:

1{"error":{"description":"Unexpected error","message":"index add 'by_email': index conflict: field 'email' with value 'ada@example.com'"}}

Ranges and order (btree)

Create an index on the monthly revenue:

curl -X POST "https://inceptiondb.hola.cloud/v1/databases/$INCEPTIONDB_DATABASE/collections/customers:createIndex" \
  -H "Api-Key: $INCEPTIONDB_API_KEY" \
  -H "Api-Secret: $INCEPTIONDB_API_SECRET" \
  -d '{"name": "by_mrr", "type": "btree", "fields": ["mrr"]}'
POST /v1/databases/$INCEPTIONDB_DATABASE/collections/customers:createIndex HTTP/1.1
Host: inceptiondb.hola.cloud
Api-Key: $INCEPTIONDB_API_KEY
Api-Secret: $INCEPTIONDB_API_SECRET

{"name": "by_mrr", "type": "btree", "fields": ["mrr"]}
package main

import (
	"fmt"
	"io"
	"net/http"
	"os"
	"encoding/json"
	"strings"
)

func main() {
	payload := map[string]any{"fields": []any{"mrr"}, "name": "by_mrr", "type": "btree"}
	bodyBytes, err := json.Marshal(payload)
	if err != nil {
		panic(err)
	}
	body := string(bodyBytes)

	req, err := http.NewRequest("POST", "https://inceptiondb.hola.cloud/v1/databases/" + os.Getenv("INCEPTIONDB_DATABASE") + "/collections/customers:createIndex", strings.NewReader(body))
	if err != nil {
		panic(err)
	}
	req.Header.Set("Api-Key", os.Getenv("INCEPTIONDB_API_KEY"))
	req.Header.Set("Api-Secret", os.Getenv("INCEPTIONDB_API_SECRET"))

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	responseBody, err := io.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(responseBody))
}
<?php
$payload = ['fields' => ['mrr'], 'name' => 'by_mrr', 'type' => 'btree'];
$body = json_encode($payload);

$ch = curl_init();

curl_setopt_array($ch, [
    CURLOPT_URL => 'https://inceptiondb.hola.cloud/v1/databases/' . getenv('INCEPTIONDB_DATABASE') . '/collections/customers:createIndex',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS => $body,
    CURLOPT_HTTPHEADER => [
        'Api-Key: ' . getenv('INCEPTIONDB_API_KEY'),
        'Api-Secret: ' . getenv('INCEPTIONDB_API_SECRET'),
    ],
]);

$response = curl_exec($ch);
if ($response === false) {
    throw new Exception(curl_error($ch));
}
curl_close($ch);

echo $response;
import os
import requests

import json

headers = {
    "Api-Key": os.environ["INCEPTIONDB_API_KEY"],
    "Api-Secret": os.environ["INCEPTIONDB_API_SECRET"],
}

payload = {"fields": ["mrr"], "name": "by_mrr", "type": "btree"}
body = json.dumps(payload)

response = requests.request(
    "POST",
    "https://inceptiondb.hola.cloud/v1/databases/" + os.environ["INCEPTIONDB_DATABASE"] + "/collections/customers:createIndex",
    headers=headers,
    data=body
)

print(response.text)
const payload = {"fields": ["mrr"], "name": "by_mrr", "type": "btree"};

const response = await fetch("https://inceptiondb.hola.cloud/v1/databases/" + process.env.INCEPTIONDB_DATABASE + "/collections/customers:createIndex", {
  method: "POST",
  headers: {
    "Api-Key": process.env.INCEPTIONDB_API_KEY,
    "Api-Secret": process.env.INCEPTIONDB_API_SECRET
  },
  body: JSON.stringify(payload)
});

console.log(await response.text());
// Fill in your values. Never put an API secret in code that runs in a public web page.
const INCEPTIONDB_DATABASE = "your-inceptiondb-database";
const INCEPTIONDB_API_KEY = "your-inceptiondb-api-key";
const INCEPTIONDB_API_SECRET = "your-inceptiondb-api-secret";

const payload = {"fields": ["mrr"], "name": "by_mrr", "type": "btree"};

const response = await fetch("https://inceptiondb.hola.cloud/v1/databases/" + INCEPTIONDB_DATABASE + "/collections/customers:createIndex", {
  method: "POST",
  headers: {
    "Api-Key": INCEPTIONDB_API_KEY,
    "Api-Secret": INCEPTIONDB_API_SECRET
  },
  body: JSON.stringify(payload)
});

const text = await response.text();
console.log(text);
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Map;
import java.util.List;

public class Main {
    public static void main(String[] args) throws Exception {
        var payload = Map.of("fields", List.of("mrr"), "name", "by_mrr", "type", "btree");
        var body = new ObjectMapper().writeValueAsString(payload);

        var request = HttpRequest.newBuilder()
            .uri(URI.create("https://inceptiondb.hola.cloud/v1/databases/" + System.getenv("INCEPTIONDB_DATABASE") + "/collections/customers:createIndex"))
            .method("POST", HttpRequest.BodyPublishers.ofString(body))
            .header("Api-Key", System.getenv("INCEPTIONDB_API_KEY"))
            .header("Api-Secret", System.getenv("INCEPTIONDB_API_SECRET"))
            .build();

        var response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}
1{"fields":["mrr"],"name":"by_mrr","sparse":false,"type":"btree","unique":false}

The customers that pay between 100 and 500, from the lowest:

curl -X POST "https://inceptiondb.hola.cloud/v1/databases/$INCEPTIONDB_DATABASE/collections/customers:find" \
  -H "Api-Key: $INCEPTIONDB_API_KEY" \
  -H "Api-Secret: $INCEPTIONDB_API_SECRET" \
  -d '{"index": "by_mrr", "from": {"mrr": 100}, "to": {"mrr": 500}, "limit": 10}'
POST /v1/databases/$INCEPTIONDB_DATABASE/collections/customers:find HTTP/1.1
Host: inceptiondb.hola.cloud
Api-Key: $INCEPTIONDB_API_KEY
Api-Secret: $INCEPTIONDB_API_SECRET

{"index": "by_mrr", "from": {"mrr": 100}, "to": {"mrr": 500}, "limit": 10}
package main

import (
	"fmt"
	"io"
	"net/http"
	"os"
	"encoding/json"
	"strings"
)

func main() {
	payload := map[string]any{"from": map[string]any{"mrr": 100}, "index": "by_mrr", "limit": 10, "to": map[string]any{"mrr": 500}}
	bodyBytes, err := json.Marshal(payload)
	if err != nil {
		panic(err)
	}
	body := string(bodyBytes)

	req, err := http.NewRequest("POST", "https://inceptiondb.hola.cloud/v1/databases/" + os.Getenv("INCEPTIONDB_DATABASE") + "/collections/customers:find", strings.NewReader(body))
	if err != nil {
		panic(err)
	}
	req.Header.Set("Api-Key", os.Getenv("INCEPTIONDB_API_KEY"))
	req.Header.Set("Api-Secret", os.Getenv("INCEPTIONDB_API_SECRET"))

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	responseBody, err := io.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(responseBody))
}
<?php
$payload = ['from' => ['mrr' => 100], 'index' => 'by_mrr', 'limit' => 10, 'to' => ['mrr' => 500]];
$body = json_encode($payload);

$ch = curl_init();

curl_setopt_array($ch, [
    CURLOPT_URL => 'https://inceptiondb.hola.cloud/v1/databases/' . getenv('INCEPTIONDB_DATABASE') . '/collections/customers:find',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS => $body,
    CURLOPT_HTTPHEADER => [
        'Api-Key: ' . getenv('INCEPTIONDB_API_KEY'),
        'Api-Secret: ' . getenv('INCEPTIONDB_API_SECRET'),
    ],
]);

$response = curl_exec($ch);
if ($response === false) {
    throw new Exception(curl_error($ch));
}
curl_close($ch);

echo $response;
import os
import requests

import json

headers = {
    "Api-Key": os.environ["INCEPTIONDB_API_KEY"],
    "Api-Secret": os.environ["INCEPTIONDB_API_SECRET"],
}

payload = {"from": {"mrr": 100}, "index": "by_mrr", "limit": 10, "to": {"mrr": 500}}
body = json.dumps(payload)

response = requests.request(
    "POST",
    "https://inceptiondb.hola.cloud/v1/databases/" + os.environ["INCEPTIONDB_DATABASE"] + "/collections/customers:find",
    headers=headers,
    data=body
)

print(response.text)
const payload = {"from": {"mrr": 100}, "index": "by_mrr", "limit": 10, "to": {"mrr": 500}};

const response = await fetch("https://inceptiondb.hola.cloud/v1/databases/" + process.env.INCEPTIONDB_DATABASE + "/collections/customers:find", {
  method: "POST",
  headers: {
    "Api-Key": process.env.INCEPTIONDB_API_KEY,
    "Api-Secret": process.env.INCEPTIONDB_API_SECRET
  },
  body: JSON.stringify(payload)
});

console.log(await response.text());
// Fill in your values. Never put an API secret in code that runs in a public web page.
const INCEPTIONDB_DATABASE = "your-inceptiondb-database";
const INCEPTIONDB_API_KEY = "your-inceptiondb-api-key";
const INCEPTIONDB_API_SECRET = "your-inceptiondb-api-secret";

const payload = {"from": {"mrr": 100}, "index": "by_mrr", "limit": 10, "to": {"mrr": 500}};

const response = await fetch("https://inceptiondb.hola.cloud/v1/databases/" + INCEPTIONDB_DATABASE + "/collections/customers:find", {
  method: "POST",
  headers: {
    "Api-Key": INCEPTIONDB_API_KEY,
    "Api-Secret": INCEPTIONDB_API_SECRET
  },
  body: JSON.stringify(payload)
});

const text = await response.text();
console.log(text);
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Map;
import java.util.List;

public class Main {
    public static void main(String[] args) throws Exception {
        var payload = Map.of("from", Map.of("mrr", 100), "index", "by_mrr", "limit", 10, "to", Map.of("mrr", 500));
        var body = new ObjectMapper().writeValueAsString(payload);

        var request = HttpRequest.newBuilder()
            .uri(URI.create("https://inceptiondb.hola.cloud/v1/databases/" + System.getenv("INCEPTIONDB_DATABASE") + "/collections/customers:find"))
            .method("POST", HttpRequest.BodyPublishers.ofString(body))
            .header("Api-Key", System.getenv("INCEPTIONDB_API_KEY"))
            .header("Api-Secret", System.getenv("INCEPTIONDB_API_SECRET"))
            .build();

        var response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}
1{"id":"ada","name":"Ada Lovelace","email":"ada@example.com","plan":"pro","country":"GB","mrr":120,"tags":["vip","beta"],"address":{"city":"London","zip":"N1"}}
2{"id":"grace","name":"Grace Hopper","email":"grace@example.com","plan":"team","country":"US","mrr":480,"tags":["vip"],"address":{"city":"New York","zip":"10001"}}

The top customers, from the highest: "reverse": true.

curl -X POST "https://inceptiondb.hola.cloud/v1/databases/$INCEPTIONDB_DATABASE/collections/customers:find" \
  -H "Api-Key: $INCEPTIONDB_API_KEY" \
  -H "Api-Secret: $INCEPTIONDB_API_SECRET" \
  -d '{"index": "by_mrr", "reverse": true, "limit": 3}'
POST /v1/databases/$INCEPTIONDB_DATABASE/collections/customers:find HTTP/1.1
Host: inceptiondb.hola.cloud
Api-Key: $INCEPTIONDB_API_KEY
Api-Secret: $INCEPTIONDB_API_SECRET

{"index": "by_mrr", "reverse": true, "limit": 3}
package main

import (
	"fmt"
	"io"
	"net/http"
	"os"
	"encoding/json"
	"strings"
)

func main() {
	payload := map[string]any{"index": "by_mrr", "limit": 3, "reverse": true}
	bodyBytes, err := json.Marshal(payload)
	if err != nil {
		panic(err)
	}
	body := string(bodyBytes)

	req, err := http.NewRequest("POST", "https://inceptiondb.hola.cloud/v1/databases/" + os.Getenv("INCEPTIONDB_DATABASE") + "/collections/customers:find", strings.NewReader(body))
	if err != nil {
		panic(err)
	}
	req.Header.Set("Api-Key", os.Getenv("INCEPTIONDB_API_KEY"))
	req.Header.Set("Api-Secret", os.Getenv("INCEPTIONDB_API_SECRET"))

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	responseBody, err := io.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(responseBody))
}
<?php
$payload = ['index' => 'by_mrr', 'limit' => 3, 'reverse' => true];
$body = json_encode($payload);

$ch = curl_init();

curl_setopt_array($ch, [
    CURLOPT_URL => 'https://inceptiondb.hola.cloud/v1/databases/' . getenv('INCEPTIONDB_DATABASE') . '/collections/customers:find',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS => $body,
    CURLOPT_HTTPHEADER => [
        'Api-Key: ' . getenv('INCEPTIONDB_API_KEY'),
        'Api-Secret: ' . getenv('INCEPTIONDB_API_SECRET'),
    ],
]);

$response = curl_exec($ch);
if ($response === false) {
    throw new Exception(curl_error($ch));
}
curl_close($ch);

echo $response;
import os
import requests

import json

headers = {
    "Api-Key": os.environ["INCEPTIONDB_API_KEY"],
    "Api-Secret": os.environ["INCEPTIONDB_API_SECRET"],
}

payload = {"index": "by_mrr", "limit": 3, "reverse": True}
body = json.dumps(payload)

response = requests.request(
    "POST",
    "https://inceptiondb.hola.cloud/v1/databases/" + os.environ["INCEPTIONDB_DATABASE"] + "/collections/customers:find",
    headers=headers,
    data=body
)

print(response.text)
const payload = {"index": "by_mrr", "limit": 3, "reverse": true};

const response = await fetch("https://inceptiondb.hola.cloud/v1/databases/" + process.env.INCEPTIONDB_DATABASE + "/collections/customers:find", {
  method: "POST",
  headers: {
    "Api-Key": process.env.INCEPTIONDB_API_KEY,
    "Api-Secret": process.env.INCEPTIONDB_API_SECRET
  },
  body: JSON.stringify(payload)
});

console.log(await response.text());
// Fill in your values. Never put an API secret in code that runs in a public web page.
const INCEPTIONDB_DATABASE = "your-inceptiondb-database";
const INCEPTIONDB_API_KEY = "your-inceptiondb-api-key";
const INCEPTIONDB_API_SECRET = "your-inceptiondb-api-secret";

const payload = {"index": "by_mrr", "limit": 3, "reverse": true};

const response = await fetch("https://inceptiondb.hola.cloud/v1/databases/" + INCEPTIONDB_DATABASE + "/collections/customers:find", {
  method: "POST",
  headers: {
    "Api-Key": INCEPTIONDB_API_KEY,
    "Api-Secret": INCEPTIONDB_API_SECRET
  },
  body: JSON.stringify(payload)
});

const text = await response.text();
console.log(text);
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Map;
import java.util.List;

public class Main {
    public static void main(String[] args) throws Exception {
        var payload = Map.of("index", "by_mrr", "limit", 3, "reverse", true);
        var body = new ObjectMapper().writeValueAsString(payload);

        var request = HttpRequest.newBuilder()
            .uri(URI.create("https://inceptiondb.hola.cloud/v1/databases/" + System.getenv("INCEPTIONDB_DATABASE") + "/collections/customers:find"))
            .method("POST", HttpRequest.BodyPublishers.ofString(body))
            .header("Api-Key", System.getenv("INCEPTIONDB_API_KEY"))
            .header("Api-Secret", System.getenv("INCEPTIONDB_API_SECRET"))
            .build();

        var response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}

Good to know:

  • from and to are optional; leave one out for an open range.
  • fields takes several fields, for example ["country", "-mrr"]: by country, and inside each country from the highest revenue (- means descending).
  • You can add a filter as well: the index chooses the order and the range, the filter discards documents.
  • "unique": true rejects repeated values, like a map index.

Word search (fts)

curl -X POST "https://inceptiondb.hola.cloud/v1/databases/$INCEPTIONDB_DATABASE/collections/customers:createIndex" \
  -H "Api-Key: $INCEPTIONDB_API_KEY" \
  -H "Api-Secret: $INCEPTIONDB_API_SECRET" \
  -d '{"name": "search_name", "type": "fts", "field": "name"}'
POST /v1/databases/$INCEPTIONDB_DATABASE/collections/customers:createIndex HTTP/1.1
Host: inceptiondb.hola.cloud
Api-Key: $INCEPTIONDB_API_KEY
Api-Secret: $INCEPTIONDB_API_SECRET

{"name": "search_name", "type": "fts", "field": "name"}
package main

import (
	"fmt"
	"io"
	"net/http"
	"os"
	"encoding/json"
	"strings"
)

func main() {
	payload := map[string]any{"field": "name", "name": "search_name", "type": "fts"}
	bodyBytes, err := json.Marshal(payload)
	if err != nil {
		panic(err)
	}
	body := string(bodyBytes)

	req, err := http.NewRequest("POST", "https://inceptiondb.hola.cloud/v1/databases/" + os.Getenv("INCEPTIONDB_DATABASE") + "/collections/customers:createIndex", strings.NewReader(body))
	if err != nil {
		panic(err)
	}
	req.Header.Set("Api-Key", os.Getenv("INCEPTIONDB_API_KEY"))
	req.Header.Set("Api-Secret", os.Getenv("INCEPTIONDB_API_SECRET"))

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	responseBody, err := io.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(responseBody))
}
<?php
$payload = ['field' => 'name', 'name' => 'search_name', 'type' => 'fts'];
$body = json_encode($payload);

$ch = curl_init();

curl_setopt_array($ch, [
    CURLOPT_URL => 'https://inceptiondb.hola.cloud/v1/databases/' . getenv('INCEPTIONDB_DATABASE') . '/collections/customers:createIndex',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS => $body,
    CURLOPT_HTTPHEADER => [
        'Api-Key: ' . getenv('INCEPTIONDB_API_KEY'),
        'Api-Secret: ' . getenv('INCEPTIONDB_API_SECRET'),
    ],
]);

$response = curl_exec($ch);
if ($response === false) {
    throw new Exception(curl_error($ch));
}
curl_close($ch);

echo $response;
import os
import requests

import json

headers = {
    "Api-Key": os.environ["INCEPTIONDB_API_KEY"],
    "Api-Secret": os.environ["INCEPTIONDB_API_SECRET"],
}

payload = {"field": "name", "name": "search_name", "type": "fts"}
body = json.dumps(payload)

response = requests.request(
    "POST",
    "https://inceptiondb.hola.cloud/v1/databases/" + os.environ["INCEPTIONDB_DATABASE"] + "/collections/customers:createIndex",
    headers=headers,
    data=body
)

print(response.text)
const payload = {"field": "name", "name": "search_name", "type": "fts"};

const response = await fetch("https://inceptiondb.hola.cloud/v1/databases/" + process.env.INCEPTIONDB_DATABASE + "/collections/customers:createIndex", {
  method: "POST",
  headers: {
    "Api-Key": process.env.INCEPTIONDB_API_KEY,
    "Api-Secret": process.env.INCEPTIONDB_API_SECRET
  },
  body: JSON.stringify(payload)
});

console.log(await response.text());
// Fill in your values. Never put an API secret in code that runs in a public web page.
const INCEPTIONDB_DATABASE = "your-inceptiondb-database";
const INCEPTIONDB_API_KEY = "your-inceptiondb-api-key";
const INCEPTIONDB_API_SECRET = "your-inceptiondb-api-secret";

const payload = {"field": "name", "name": "search_name", "type": "fts"};

const response = await fetch("https://inceptiondb.hola.cloud/v1/databases/" + INCEPTIONDB_DATABASE + "/collections/customers:createIndex", {
  method: "POST",
  headers: {
    "Api-Key": INCEPTIONDB_API_KEY,
    "Api-Secret": INCEPTIONDB_API_SECRET
  },
  body: JSON.stringify(payload)
});

const text = await response.text();
console.log(text);
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Map;
import java.util.List;

public class Main {
    public static void main(String[] args) throws Exception {
        var payload = Map.of("field", "name", "name", "search_name", "type", "fts");
        var body = new ObjectMapper().writeValueAsString(payload);

        var request = HttpRequest.newBuilder()
            .uri(URI.create("https://inceptiondb.hola.cloud/v1/databases/" + System.getenv("INCEPTIONDB_DATABASE") + "/collections/customers:createIndex"))
            .method("POST", HttpRequest.BodyPublishers.ofString(body))
            .header("Api-Key", System.getenv("INCEPTIONDB_API_KEY"))
            .header("Api-Secret", System.getenv("INCEPTIONDB_API_SECRET"))
            .build();

        var response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}

Find the customers with grace in their name, in upper or lower case:

curl -X POST "https://inceptiondb.hola.cloud/v1/databases/$INCEPTIONDB_DATABASE/collections/customers:find" \
  -H "Api-Key: $INCEPTIONDB_API_KEY" \
  -H "Api-Secret: $INCEPTIONDB_API_SECRET" \
  -d '{"index": "search_name", "match": "grace", "limit": 10}'
POST /v1/databases/$INCEPTIONDB_DATABASE/collections/customers:find HTTP/1.1
Host: inceptiondb.hola.cloud
Api-Key: $INCEPTIONDB_API_KEY
Api-Secret: $INCEPTIONDB_API_SECRET

{"index": "search_name", "match": "grace", "limit": 10}
package main

import (
	"fmt"
	"io"
	"net/http"
	"os"
	"encoding/json"
	"strings"
)

func main() {
	payload := map[string]any{"index": "search_name", "limit": 10, "match": "grace"}
	bodyBytes, err := json.Marshal(payload)
	if err != nil {
		panic(err)
	}
	body := string(bodyBytes)

	req, err := http.NewRequest("POST", "https://inceptiondb.hola.cloud/v1/databases/" + os.Getenv("INCEPTIONDB_DATABASE") + "/collections/customers:find", strings.NewReader(body))
	if err != nil {
		panic(err)
	}
	req.Header.Set("Api-Key", os.Getenv("INCEPTIONDB_API_KEY"))
	req.Header.Set("Api-Secret", os.Getenv("INCEPTIONDB_API_SECRET"))

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	responseBody, err := io.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(responseBody))
}
<?php
$payload = ['index' => 'search_name', 'limit' => 10, 'match' => 'grace'];
$body = json_encode($payload);

$ch = curl_init();

curl_setopt_array($ch, [
    CURLOPT_URL => 'https://inceptiondb.hola.cloud/v1/databases/' . getenv('INCEPTIONDB_DATABASE') . '/collections/customers:find',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS => $body,
    CURLOPT_HTTPHEADER => [
        'Api-Key: ' . getenv('INCEPTIONDB_API_KEY'),
        'Api-Secret: ' . getenv('INCEPTIONDB_API_SECRET'),
    ],
]);

$response = curl_exec($ch);
if ($response === false) {
    throw new Exception(curl_error($ch));
}
curl_close($ch);

echo $response;
import os
import requests

import json

headers = {
    "Api-Key": os.environ["INCEPTIONDB_API_KEY"],
    "Api-Secret": os.environ["INCEPTIONDB_API_SECRET"],
}

payload = {"index": "search_name", "limit": 10, "match": "grace"}
body = json.dumps(payload)

response = requests.request(
    "POST",
    "https://inceptiondb.hola.cloud/v1/databases/" + os.environ["INCEPTIONDB_DATABASE"] + "/collections/customers:find",
    headers=headers,
    data=body
)

print(response.text)
const payload = {"index": "search_name", "limit": 10, "match": "grace"};

const response = await fetch("https://inceptiondb.hola.cloud/v1/databases/" + process.env.INCEPTIONDB_DATABASE + "/collections/customers:find", {
  method: "POST",
  headers: {
    "Api-Key": process.env.INCEPTIONDB_API_KEY,
    "Api-Secret": process.env.INCEPTIONDB_API_SECRET
  },
  body: JSON.stringify(payload)
});

console.log(await response.text());
// Fill in your values. Never put an API secret in code that runs in a public web page.
const INCEPTIONDB_DATABASE = "your-inceptiondb-database";
const INCEPTIONDB_API_KEY = "your-inceptiondb-api-key";
const INCEPTIONDB_API_SECRET = "your-inceptiondb-api-secret";

const payload = {"index": "search_name", "limit": 10, "match": "grace"};

const response = await fetch("https://inceptiondb.hola.cloud/v1/databases/" + INCEPTIONDB_DATABASE + "/collections/customers:find", {
  method: "POST",
  headers: {
    "Api-Key": INCEPTIONDB_API_KEY,
    "Api-Secret": INCEPTIONDB_API_SECRET
  },
  body: JSON.stringify(payload)
});

const text = await response.text();
console.log(text);
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Map;
import java.util.List;

public class Main {
    public static void main(String[] args) throws Exception {
        var payload = Map.of("index", "search_name", "limit", 10, "match", "grace");
        var body = new ObjectMapper().writeValueAsString(payload);

        var request = HttpRequest.newBuilder()
            .uri(URI.create("https://inceptiondb.hola.cloud/v1/databases/" + System.getenv("INCEPTIONDB_DATABASE") + "/collections/customers:find"))
            .method("POST", HttpRequest.BodyPublishers.ofString(body))
            .header("Api-Key", System.getenv("INCEPTIONDB_API_KEY"))
            .header("Api-Secret", System.getenv("INCEPTIONDB_API_SECRET"))
            .build();

        var response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}
1{"id":"grace","name":"Grace Hopper","email":"grace@example.com","plan":"team","country":"US","mrr":480,"tags":["vip"],"address":{"city":"New York","zip":"10001"}}

Documents without the field

Documents that do not have the indexed field are stored as usual, but they are not part of the index: a query that uses the index does not return them. A query without index still finds them. Create indexes with "sparse": true to make that explicit:

curl -X POST "https://inceptiondb.hola.cloud/v1/databases/$INCEPTIONDB_DATABASE/collections/customers:createIndex" \
  -H "Api-Key: $INCEPTIONDB_API_KEY" \
  -H "Api-Secret: $INCEPTIONDB_API_SECRET" \
  -d '{"name": "by_company", "type": "btree", "fields": ["company"], "sparse": true}'
POST /v1/databases/$INCEPTIONDB_DATABASE/collections/customers:createIndex HTTP/1.1
Host: inceptiondb.hola.cloud
Api-Key: $INCEPTIONDB_API_KEY
Api-Secret: $INCEPTIONDB_API_SECRET

{"name": "by_company", "type": "btree", "fields": ["company"], "sparse": true}
package main

import (
	"fmt"
	"io"
	"net/http"
	"os"
	"encoding/json"
	"strings"
)

func main() {
	payload := map[string]any{"fields": []any{"company"}, "name": "by_company", "sparse": true, "type": "btree"}
	bodyBytes, err := json.Marshal(payload)
	if err != nil {
		panic(err)
	}
	body := string(bodyBytes)

	req, err := http.NewRequest("POST", "https://inceptiondb.hola.cloud/v1/databases/" + os.Getenv("INCEPTIONDB_DATABASE") + "/collections/customers:createIndex", strings.NewReader(body))
	if err != nil {
		panic(err)
	}
	req.Header.Set("Api-Key", os.Getenv("INCEPTIONDB_API_KEY"))
	req.Header.Set("Api-Secret", os.Getenv("INCEPTIONDB_API_SECRET"))

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	responseBody, err := io.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(responseBody))
}
<?php
$payload = ['fields' => ['company'], 'name' => 'by_company', 'sparse' => true, 'type' => 'btree'];
$body = json_encode($payload);

$ch = curl_init();

curl_setopt_array($ch, [
    CURLOPT_URL => 'https://inceptiondb.hola.cloud/v1/databases/' . getenv('INCEPTIONDB_DATABASE') . '/collections/customers:createIndex',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS => $body,
    CURLOPT_HTTPHEADER => [
        'Api-Key: ' . getenv('INCEPTIONDB_API_KEY'),
        'Api-Secret: ' . getenv('INCEPTIONDB_API_SECRET'),
    ],
]);

$response = curl_exec($ch);
if ($response === false) {
    throw new Exception(curl_error($ch));
}
curl_close($ch);

echo $response;
import os
import requests

import json

headers = {
    "Api-Key": os.environ["INCEPTIONDB_API_KEY"],
    "Api-Secret": os.environ["INCEPTIONDB_API_SECRET"],
}

payload = {"fields": ["company"], "name": "by_company", "sparse": True, "type": "btree"}
body = json.dumps(payload)

response = requests.request(
    "POST",
    "https://inceptiondb.hola.cloud/v1/databases/" + os.environ["INCEPTIONDB_DATABASE"] + "/collections/customers:createIndex",
    headers=headers,
    data=body
)

print(response.text)
const payload = {"fields": ["company"], "name": "by_company", "sparse": true, "type": "btree"};

const response = await fetch("https://inceptiondb.hola.cloud/v1/databases/" + process.env.INCEPTIONDB_DATABASE + "/collections/customers:createIndex", {
  method: "POST",
  headers: {
    "Api-Key": process.env.INCEPTIONDB_API_KEY,
    "Api-Secret": process.env.INCEPTIONDB_API_SECRET
  },
  body: JSON.stringify(payload)
});

console.log(await response.text());
// Fill in your values. Never put an API secret in code that runs in a public web page.
const INCEPTIONDB_DATABASE = "your-inceptiondb-database";
const INCEPTIONDB_API_KEY = "your-inceptiondb-api-key";
const INCEPTIONDB_API_SECRET = "your-inceptiondb-api-secret";

const payload = {"fields": ["company"], "name": "by_company", "sparse": true, "type": "btree"};

const response = await fetch("https://inceptiondb.hola.cloud/v1/databases/" + INCEPTIONDB_DATABASE + "/collections/customers:createIndex", {
  method: "POST",
  headers: {
    "Api-Key": INCEPTIONDB_API_KEY,
    "Api-Secret": INCEPTIONDB_API_SECRET
  },
  body: JSON.stringify(payload)
});

const text = await response.text();
console.log(text);
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Map;
import java.util.List;

public class Main {
    public static void main(String[] args) throws Exception {
        var payload = Map.of("fields", List.of("company"), "name", "by_company", "sparse", true, "type", "btree");
        var body = new ObjectMapper().writeValueAsString(payload);

        var request = HttpRequest.newBuilder()
            .uri(URI.create("https://inceptiondb.hola.cloud/v1/databases/" + System.getenv("INCEPTIONDB_DATABASE") + "/collections/customers:createIndex"))
            .method("POST", HttpRequest.BodyPublishers.ofString(body))
            .header("Api-Key", System.getenv("INCEPTIONDB_API_KEY"))
            .header("Api-Secret", System.getenv("INCEPTIONDB_API_SECRET"))
            .build();

        var response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}

List and delete indexes

curl -X POST "https://inceptiondb.hola.cloud/v1/databases/$INCEPTIONDB_DATABASE/collections/customers:listIndexes" \
  -H "Api-Key: $INCEPTIONDB_API_KEY" \
  -H "Api-Secret: $INCEPTIONDB_API_SECRET"
POST /v1/databases/$INCEPTIONDB_DATABASE/collections/customers:listIndexes HTTP/1.1
Host: inceptiondb.hola.cloud
Api-Key: $INCEPTIONDB_API_KEY
Api-Secret: $INCEPTIONDB_API_SECRET
package main

import (
	"fmt"
	"io"
	"net/http"
	"os"
)

func main() {
	req, err := http.NewRequest("POST", "https://inceptiondb.hola.cloud/v1/databases/" + os.Getenv("INCEPTIONDB_DATABASE") + "/collections/customers:listIndexes", nil)
	if err != nil {
		panic(err)
	}
	req.Header.Set("Api-Key", os.Getenv("INCEPTIONDB_API_KEY"))
	req.Header.Set("Api-Secret", os.Getenv("INCEPTIONDB_API_SECRET"))

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	responseBody, err := io.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(responseBody))
}
<?php
$ch = curl_init();

curl_setopt_array($ch, [
    CURLOPT_URL => 'https://inceptiondb.hola.cloud/v1/databases/' . getenv('INCEPTIONDB_DATABASE') . '/collections/customers:listIndexes',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_HTTPHEADER => [
        'Api-Key: ' . getenv('INCEPTIONDB_API_KEY'),
        'Api-Secret: ' . getenv('INCEPTIONDB_API_SECRET'),
    ],
]);

$response = curl_exec($ch);
if ($response === false) {
    throw new Exception(curl_error($ch));
}
curl_close($ch);

echo $response;
import os
import requests

headers = {
    "Api-Key": os.environ["INCEPTIONDB_API_KEY"],
    "Api-Secret": os.environ["INCEPTIONDB_API_SECRET"],
}

response = requests.request(
    "POST",
    "https://inceptiondb.hola.cloud/v1/databases/" + os.environ["INCEPTIONDB_DATABASE"] + "/collections/customers:listIndexes",
    headers=headers
)

print(response.text)
const response = await fetch("https://inceptiondb.hola.cloud/v1/databases/" + process.env.INCEPTIONDB_DATABASE + "/collections/customers:listIndexes", {
  method: "POST",
  headers: {
    "Api-Key": process.env.INCEPTIONDB_API_KEY,
    "Api-Secret": process.env.INCEPTIONDB_API_SECRET
  }
});

console.log(await response.text());
// Fill in your values. Never put an API secret in code that runs in a public web page.
const INCEPTIONDB_DATABASE = "your-inceptiondb-database";
const INCEPTIONDB_API_KEY = "your-inceptiondb-api-key";
const INCEPTIONDB_API_SECRET = "your-inceptiondb-api-secret";

const response = await fetch("https://inceptiondb.hola.cloud/v1/databases/" + INCEPTIONDB_DATABASE + "/collections/customers:listIndexes", {
  method: "POST",
  headers: {
    "Api-Key": INCEPTIONDB_API_KEY,
    "Api-Secret": INCEPTIONDB_API_SECRET
  }
});

const text = await response.text();
console.log(text);
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
    public static void main(String[] args) throws Exception {
        var request = HttpRequest.newBuilder()
            .uri(URI.create("https://inceptiondb.hola.cloud/v1/databases/" + System.getenv("INCEPTIONDB_DATABASE") + "/collections/customers:listIndexes"))
            .method("POST", HttpRequest.BodyPublishers.noBody())
            .header("Api-Key", System.getenv("INCEPTIONDB_API_KEY"))
            .header("Api-Secret", System.getenv("INCEPTIONDB_API_SECRET"))
            .build();

        var response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}
1[{"fields":["company"],"name":"by_company","sparse":true,"type":"btree","unique":false},{"field":"email","name":"by_email","sparse":false,"type":"map"},{"fields":["mrr"],"name":"by_mrr","sparse":false,"type":"btree","unique":false},{"field":"name","name":"search_name","type":"fts"}]

Deleting an index does not touch the documents (204 No Content):

curl -X POST "https://inceptiondb.hola.cloud/v1/databases/$INCEPTIONDB_DATABASE/collections/customers:dropIndex" \
  -H "Api-Key: $INCEPTIONDB_API_KEY" \
  -H "Api-Secret: $INCEPTIONDB_API_SECRET" \
  -d '{"name": "by_mrr"}'
POST /v1/databases/$INCEPTIONDB_DATABASE/collections/customers:dropIndex HTTP/1.1
Host: inceptiondb.hola.cloud
Api-Key: $INCEPTIONDB_API_KEY
Api-Secret: $INCEPTIONDB_API_SECRET

{"name": "by_mrr"}
package main

import (
	"fmt"
	"io"
	"net/http"
	"os"
	"encoding/json"
	"strings"
)

func main() {
	payload := map[string]any{"name": "by_mrr"}
	bodyBytes, err := json.Marshal(payload)
	if err != nil {
		panic(err)
	}
	body := string(bodyBytes)

	req, err := http.NewRequest("POST", "https://inceptiondb.hola.cloud/v1/databases/" + os.Getenv("INCEPTIONDB_DATABASE") + "/collections/customers:dropIndex", strings.NewReader(body))
	if err != nil {
		panic(err)
	}
	req.Header.Set("Api-Key", os.Getenv("INCEPTIONDB_API_KEY"))
	req.Header.Set("Api-Secret", os.Getenv("INCEPTIONDB_API_SECRET"))

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	responseBody, err := io.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(responseBody))
}
<?php
$payload = ['name' => 'by_mrr'];
$body = json_encode($payload);

$ch = curl_init();

curl_setopt_array($ch, [
    CURLOPT_URL => 'https://inceptiondb.hola.cloud/v1/databases/' . getenv('INCEPTIONDB_DATABASE') . '/collections/customers:dropIndex',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS => $body,
    CURLOPT_HTTPHEADER => [
        'Api-Key: ' . getenv('INCEPTIONDB_API_KEY'),
        'Api-Secret: ' . getenv('INCEPTIONDB_API_SECRET'),
    ],
]);

$response = curl_exec($ch);
if ($response === false) {
    throw new Exception(curl_error($ch));
}
curl_close($ch);

echo $response;
import os
import requests

import json

headers = {
    "Api-Key": os.environ["INCEPTIONDB_API_KEY"],
    "Api-Secret": os.environ["INCEPTIONDB_API_SECRET"],
}

payload = {"name": "by_mrr"}
body = json.dumps(payload)

response = requests.request(
    "POST",
    "https://inceptiondb.hola.cloud/v1/databases/" + os.environ["INCEPTIONDB_DATABASE"] + "/collections/customers:dropIndex",
    headers=headers,
    data=body
)

print(response.text)
const payload = {"name": "by_mrr"};

const response = await fetch("https://inceptiondb.hola.cloud/v1/databases/" + process.env.INCEPTIONDB_DATABASE + "/collections/customers:dropIndex", {
  method: "POST",
  headers: {
    "Api-Key": process.env.INCEPTIONDB_API_KEY,
    "Api-Secret": process.env.INCEPTIONDB_API_SECRET
  },
  body: JSON.stringify(payload)
});

console.log(await response.text());
// Fill in your values. Never put an API secret in code that runs in a public web page.
const INCEPTIONDB_DATABASE = "your-inceptiondb-database";
const INCEPTIONDB_API_KEY = "your-inceptiondb-api-key";
const INCEPTIONDB_API_SECRET = "your-inceptiondb-api-secret";

const payload = {"name": "by_mrr"};

const response = await fetch("https://inceptiondb.hola.cloud/v1/databases/" + INCEPTIONDB_DATABASE + "/collections/customers:dropIndex", {
  method: "POST",
  headers: {
    "Api-Key": INCEPTIONDB_API_KEY,
    "Api-Secret": INCEPTIONDB_API_SECRET
  },
  body: JSON.stringify(payload)
});

const text = await response.text();
console.log(text);
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Map;
import java.util.List;

public class Main {
    public static void main(String[] args) throws Exception {
        var payload = Map.of("name", "by_mrr");
        var body = new ObjectMapper().writeValueAsString(payload);

        var request = HttpRequest.newBuilder()
            .uri(URI.create("https://inceptiondb.hola.cloud/v1/databases/" + System.getenv("INCEPTIONDB_DATABASE") + "/collections/customers:dropIndex"))
            .method("POST", HttpRequest.BodyPublishers.ofString(body))
            .header("Api-Key", System.getenv("INCEPTIONDB_API_KEY"))
            .header("Api-Secret", System.getenv("INCEPTIONDB_API_SECRET"))
            .build();

        var response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}

In the console, the Schema tab creates an index on any field in one click.

Comments

Leave a comment