Consultas

:find devuelve los documentos que cumplen un filtro, como JSON Lines (un documento por línea). Los ejemplos usan la colección customers y las variables de entorno de Primeros pasos.

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 '{"filter": {"plan": "pro"}, "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

{"filter": {"plan": "pro"}, "limit": 10}
package main

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

func main() {
	payload := map[string]any{"filter": map[string]any{"plan": "pro"}, "limit": 10}
	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 = ['filter' => ['plan' => 'pro'], 'limit' => 10];
$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 = {"filter": {"plan": "pro"}, "limit": 10}
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 = {"filter": {"plan": "pro"}, "limit": 10};

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 = {"filter": {"plan": "pro"}, "limit": 10};

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("filter", Map.of("plan", "pro"), "limit", 10);
        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"}}

El cuerpo de la petición:

Campo Por defecto Significado
filter {} (todo) Condiciones que deben cumplir los documentos.
limit 1 Cuántos documentos devolver. -1 los devuelve todos.
skip 0 Cuántos documentos que coinciden saltar primero, para paginar.
index ninguno Responder la consulta con un índice.

Cuando nada coincide, la respuesta es 204 No Content con el cuerpo vacío.

Filtros

Un filtro es un objeto JSON. Cada campo es una condición y deben cumplirse todas.

Igual a un valor: {"plan": "pro", "country": "GB"}.

Comparar con un operador:

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 '{"filter": {"mrr": {"$ge": 100, "$lt": 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

{"filter": {"mrr": {"$ge": 100, "$lt": 500}}, "limit": 10}
package main

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

func main() {
	payload := map[string]any{"filter": map[string]any{"mrr": map[string]any{"$ge": 100, "$lt": 500}}, "limit": 10}
	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 = ['filter' => ['mrr' => ['$ge' => 100, '$lt' => 500]], 'limit' => 10];
$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 = {"filter": {"mrr": {"$ge": 100, "$lt": 500}}, "limit": 10}
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 = {"filter": {"mrr": {"$ge": 100, "$lt": 500}}, "limit": 10};

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 = {"filter": {"mrr": {"$ge": 100, "$lt": 500}}, "limit": 10};

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("filter", Map.of("mrr", Map.of("$ge", 100, "$lt", 500)), "limit", 10);
        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());
    }
}
Operador Coincide cuando el campo Ejemplo
$eq es igual al valor {"plan": {"$eq": "pro"}}
$ne no es igual {"plan": {"$ne": "free"}}
$gt es mayor que {"mrr": {"$gt": 100}}
$ge es mayor o igual que {"mrr": {"$ge": 100}}
$lt es menor que {"mrr": {"$lt": 100}}
$le es menor o igual que {"mrr": {"$le": 100}}
$in es uno de los valores {"plan": {"$in": ["pro", "team"]}}
$nin no es ninguno de los valores {"country": {"$nin": ["US", "GB"]}}
$contains es un texto que contiene el valor {"email": {"$contains": "@example.com"}}

Usa exactamente estos nombres: $ge y $le, no $gte ni $lte. Un filtro con un operador que no existe no coincide con ningún documento.

Las fechas escritas como texto en formato ISO ("2026-10-28T09:30:00Z") se comparan en orden cronológico: {"created_at": {"$gt": "2026-01-01"}}.

Combinar condiciones

Varios campos deben cumplirse todos. Para que coincida cualquiera de varias condiciones, usa $or:

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 '{"filter": {"$or": [{"plan": "team"}, {"country": "US"}]}, "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

{"filter": {"$or": [{"plan": "team"}, {"country": "US"}]}, "limit": 10}
package main

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

func main() {
	payload := map[string]any{"filter": map[string]any{"$or": []any{map[string]any{"plan": "team"}, map[string]any{"country": "US"}}}, "limit": 10}
	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 = ['filter' => ['$or' => [['plan' => 'team'], ['country' => 'US']]], 'limit' => 10];
$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 = {"filter": {"$or": [{"plan": "team"}, {"country": "US"}]}, "limit": 10}
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 = {"filter": {"$or": [{"plan": "team"}, {"country": "US"}]}, "limit": 10};

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 = {"filter": {"$or": [{"plan": "team"}, {"country": "US"}]}, "limit": 10};

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("filter", Map.of("$or", List.of(Map.of("plan", "team"), Map.of("country", "US"))), "limit", 10);
        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"}}

$and también recibe una lista, y sirve para aplicar dos condiciones al mismo campo.

Campos anidados

Llega a un campo dentro de un objeto con un punto:

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 '{"filter": {"address.city": "London"}, "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

{"filter": {"address.city": "London"}, "limit": 10}
package main

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

func main() {
	payload := map[string]any{"filter": map[string]any{"address.city": "London"}, "limit": 10}
	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 = ['filter' => ['address.city' => 'London'], 'limit' => 10];
$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 = {"filter": {"address.city": "London"}, "limit": 10}
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 = {"filter": {"address.city": "London"}, "limit": 10};

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 = {"filter": {"address.city": "London"}, "limit": 10};

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("filter", Map.of("address.city", "London"), "limit", 10);
        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"}}

Arrays

Una condición sobre un campo que es un array se cumple cuando cualquiera de sus elementos la cumple. Los clientes con la etiqueta vip:

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 '{"filter": {"tags": "vip"}, "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

{"filter": {"tags": "vip"}, "limit": 10}
package main

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

func main() {
	payload := map[string]any{"filter": map[string]any{"tags": "vip"}, "limit": 10}
	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 = ['filter' => ['tags' => 'vip'], 'limit' => 10];
$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 = {"filter": {"tags": "vip"}, "limit": 10}
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 = {"filter": {"tags": "vip"}, "limit": 10};

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 = {"filter": {"tags": "vip"}, "limit": 10};

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("filter", Map.of("tags", "vip"), "limit", 10);
        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"}}

Paginación

Combina skip y limit. La segunda página de 25 documentos:

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 '{"filter": {}, "skip": 25, "limit": 25}'
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

{"filter": {}, "skip": 25, "limit": 25}
package main

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

func main() {
	payload := map[string]any{"filter": map[string]any{}, "limit": 25, "skip": 25}
	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 = ['filter' => [], 'limit' => 25, 'skip' => 25];
$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 = {"filter": {}, "limit": 25, "skip": 25}
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 = {"filter": {}, "limit": 25, "skip": 25};

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 = {"filter": {}, "limit": 25, "skip": 25};

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("filter", Map.of(), "limit", 25, "skip", 25);
        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());
    }
}

Sin índice, los documentos no llegan en ningún orden concreto. Para recibirlos ordenados, o para que las consultas sobre colecciones grandes sean rápidas, usa un índice.

Pruébalo en la consola

La consola ejecuta tu filtro mientras escribes, sugiere los nombres de campo de tus datos y muestra filtros de ejemplo sacados de ellos. La pestaña Schema lista cada campo con su tipo y sus valores más comunes.

Comentarios

Deja un comentario