Primeros pasos
En cinco minutos vas a crear una colección, guardar algunos clientes, consultarlos, cambiar uno y borrar otro. Todos los comandos se pueden copiar y pegar tal cual.
1. Consigue tus credenciales
- Abre la consola de InceptionDB e inicia sesión.
- Crea una base de datos (por ejemplo
my-app) o elige una que ya tengas. - Abre API keys & settings y crea una API key. El secreto se muestra una sola vez: cópialo ahora.
La consola te da los tres valores listos para pegar en un terminal. Expórtalos como variables de entorno, así nunca acaban en tu código:
1export INCEPTIONDB_DATABASE="your-database-id"
2export INCEPTIONDB_API_KEY="your-api-key"
3export INCEPTIONDB_API_SECRET="your-api-secret"
Todos los ejemplos de esta documentación leen estas variables, también las versiones en Go, Python, Node.js, PHP y Java.
2. Crea una colección
Una colección agrupa documentos. Crea una llamada customers:
curl -X POST "https://inceptiondb.hola.cloud/v1/databases/$INCEPTIONDB_DATABASE/collections" \
-H "Api-Key: $INCEPTIONDB_API_KEY" \
-H "Api-Secret: $INCEPTIONDB_API_SECRET" \
-d '{"name": "customers"}'POST /v1/databases/$INCEPTIONDB_DATABASE/collections HTTP/1.1
Host: inceptiondb.hola.cloud
Api-Key: $INCEPTIONDB_API_KEY
Api-Secret: $INCEPTIONDB_API_SECRET
{"name": "customers"}package main
import (
"fmt"
"io"
"net/http"
"os"
"encoding/json"
"strings"
)
func main() {
payload := map[string]any{"name": "customers"}
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", 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' => 'customers'];
$body = json_encode($payload);
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => 'https://inceptiondb.hola.cloud/v1/databases/' . getenv('INCEPTIONDB_DATABASE') . '/collections',
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": "customers"}
body = json.dumps(payload)
response = requests.request(
"POST",
"https://inceptiondb.hola.cloud/v1/databases/" + os.environ["INCEPTIONDB_DATABASE"] + "/collections",
headers=headers,
data=body
)
print(response.text)
const payload = {"name": "customers"};
const response = await fetch("https://inceptiondb.hola.cloud/v1/databases/" + process.env.INCEPTIONDB_DATABASE + "/collections", {
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": "customers"};
const response = await fetch("https://inceptiondb.hola.cloud/v1/databases/" + INCEPTIONDB_DATABASE + "/collections", {
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", "customers");
var body = new ObjectMapper().writeValueAsString(payload);
var request = HttpRequest.newBuilder()
.uri(URI.create("https://inceptiondb.hola.cloud/v1/databases/" + System.getenv("INCEPTIONDB_DATABASE") + "/collections"))
.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());
}
}Respuesta (201 Created):
1{"defaults":{"id":"uuid()"},"indexes":0,"name":"customers","total":0}
defaults indica que un documento sin id recibe uno aleatorio.
3. Inserta documentos
Envía un documento JSON por línea (un formato llamado JSON Lines):
curl -X POST "https://inceptiondb.hola.cloud/v1/databases/$INCEPTIONDB_DATABASE/collections/customers:insert" \
-H "Api-Key: $INCEPTIONDB_API_KEY" \
-H "Api-Secret: $INCEPTIONDB_API_SECRET" \
--data-binary '{"id":"ada","name":"Ada Lovelace","email":"ada@example.com","plan":"pro","country":"GB","mrr":120,"tags":["vip","beta"],"address":{"city":"London","zip":"N1"}}
{"id":"alan","name":"Alan Turing","email":"alan@example.com","plan":"free","country":"GB","mrr":0,"tags":["beta"],"address":{"city":"Manchester","zip":"M1"}}
{"id":"grace","name":"Grace Hopper","email":"grace@example.com","plan":"team","country":"US","mrr":480,"tags":["vip"],"address":{"city":"New York","zip":"10001"}}'POST /v1/databases/$INCEPTIONDB_DATABASE/collections/customers:insert HTTP/1.1
Host: inceptiondb.hola.cloud
Api-Key: $INCEPTIONDB_API_KEY
Api-Secret: $INCEPTIONDB_API_SECRET
{"id":"ada","name":"Ada Lovelace","email":"ada@example.com","plan":"pro","country":"GB","mrr":120,"tags":["vip","beta"],"address":{"city":"London","zip":"N1"}}
{"id":"alan","name":"Alan Turing","email":"alan@example.com","plan":"free","country":"GB","mrr":0,"tags":["beta"],"address":{"city":"Manchester","zip":"M1"}}
{"id":"grace","name":"Grace Hopper","email":"grace@example.com","plan":"team","country":"US","mrr":480,"tags":["vip"],"address":{"city":"New York","zip":"10001"}}package main
import (
"fmt"
"io"
"net/http"
"os"
"encoding/json"
"strings"
)
func main() {
payload := map[string]any{"address": map[string]any{"city": "London", "zip": "N1"}, "country": "GB", "email": "ada@example.com", "id": "ada", "mrr": 120, "name": "Ada Lovelace", "plan": "pro", "tags": []any{"vip", "beta"}}
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:insert", 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 = ['address' => ['city' => 'London', 'zip' => 'N1'], 'country' => 'GB', 'email' => 'ada@example.com', 'id' => 'ada', 'mrr' => 120, 'name' => 'Ada Lovelace', 'plan' => 'pro', 'tags' => ['vip', 'beta']];
$body = json_encode($payload);
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => 'https://inceptiondb.hola.cloud/v1/databases/' . getenv('INCEPTIONDB_DATABASE') . '/collections/customers:insert',
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 = {"address": {"city": "London", "zip": "N1"}, "country": "GB", "email": "ada@example.com", "id": "ada", "mrr": 120, "name": "Ada Lovelace", "plan": "pro", "tags": ["vip", "beta"]}
body = json.dumps(payload)
response = requests.request(
"POST",
"https://inceptiondb.hola.cloud/v1/databases/" + os.environ["INCEPTIONDB_DATABASE"] + "/collections/customers:insert",
headers=headers,
data=body
)
print(response.text)
const payload = {"address": {"city": "London", "zip": "N1"}, "country": "GB", "email": "ada@example.com", "id": "ada", "mrr": 120, "name": "Ada Lovelace", "plan": "pro", "tags": ["vip", "beta"]};
const response = await fetch("https://inceptiondb.hola.cloud/v1/databases/" + process.env.INCEPTIONDB_DATABASE + "/collections/customers:insert", {
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 = {"address": {"city": "London", "zip": "N1"}, "country": "GB", "email": "ada@example.com", "id": "ada", "mrr": 120, "name": "Ada Lovelace", "plan": "pro", "tags": ["vip", "beta"]};
const response = await fetch("https://inceptiondb.hola.cloud/v1/databases/" + INCEPTIONDB_DATABASE + "/collections/customers:insert", {
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("address", Map.of("city", "London", "zip", "N1"), "country", "GB", "email", "ada@example.com", "id", "ada", "mrr", 120, "name", "Ada Lovelace", "plan", "pro", "tags", List.of("vip", "beta"));
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:insert"))
.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());
}
}La respuesta (201 Created) trae los documentos guardados, uno por línea:
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":"alan","name":"Alan Turing","email":"alan@example.com","plan":"free","country":"GB","mrr":0,"tags":["beta"],"address":{"city":"Manchester","zip":"M1"}}
3{"id":"grace","name":"Grace Hopper","email":"grace@example.com","plan":"team","country":"US","mrr":480,"tags":["vip"],"address":{"city":"New York","zip":"10001"}}
4. Consulta
Busca los clientes del Reino Unido. limit es cuántos documentos quieres recibir: sin él recibes solo uno.
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": {"country": "GB"}, "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": {"country": "GB"}, "limit": 10}package main
import (
"fmt"
"io"
"net/http"
"os"
"encoding/json"
"strings"
)
func main() {
payload := map[string]any{"filter": map[string]any{"country": "GB"}, "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' => ['country' => 'GB'], '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": {"country": "GB"}, "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": {"country": "GB"}, "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": {"country": "GB"}, "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("country", "GB"), "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":"alan","name":"Alan Turing","email":"alan@example.com","plan":"free","country":"GB","mrr":0,"tags":["beta"],"address":{"city":"Manchester","zip":"M1"}}
Los filtros también comparan números, miran dentro de arrays y objetos anidados, y combinan condiciones. Los clientes que pagan más de 100 al mes:
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": {"$gt": 100}}, "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": {"$gt": 100}}, "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{"$gt": 100}}, "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' => ['$gt' => 100]], '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": {"$gt": 100}}, "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": {"$gt": 100}}, "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": {"$gt": 100}}, "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("$gt", 100)), "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"}}
En Consultas están todos los operadores.
5. Lee un documento
curl "https://inceptiondb.hola.cloud/v1/databases/$INCEPTIONDB_DATABASE/collections/customers/documents/ada" \
-H "Api-Key: $INCEPTIONDB_API_KEY" \
-H "Api-Secret: $INCEPTIONDB_API_SECRET"GET /v1/databases/$INCEPTIONDB_DATABASE/collections/customers/documents/ada 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("GET", "https://inceptiondb.hola.cloud/v1/databases/" + os.Getenv("INCEPTIONDB_DATABASE") + "/collections/customers/documents/ada", 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/documents/ada',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'GET',
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(
"GET",
"https://inceptiondb.hola.cloud/v1/databases/" + os.environ["INCEPTIONDB_DATABASE"] + "/collections/customers/documents/ada",
headers=headers
)
print(response.text)
const response = await fetch("https://inceptiondb.hola.cloud/v1/databases/" + process.env.INCEPTIONDB_DATABASE + "/collections/customers/documents/ada", {
method: "GET",
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/documents/ada", {
method: "GET",
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/documents/ada"))
.method("GET", 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());
}
}El documento viene en document:
1{"id":"ada","document":{"address":{"city":"London","zip":"N1"},"country":"GB","email":"ada@example.com","id":"ada","mrr":120,"name":"Ada Lovelace","plan":"pro","tags":["vip","beta"]},"source":{"type":"fullscan"}}
6. Actualiza un documento
Alan se pasa al plan pro. Un patch cambia solo los campos que envías:
curl -X POST "https://inceptiondb.hola.cloud/v1/databases/$INCEPTIONDB_DATABASE/collections/customers:patch" \
-H "Api-Key: $INCEPTIONDB_API_KEY" \
-H "Api-Secret: $INCEPTIONDB_API_SECRET" \
-d '{"filter": {"id": "alan"}, "patch": {"plan": "pro", "mrr": 120}}'POST /v1/databases/$INCEPTIONDB_DATABASE/collections/customers:patch HTTP/1.1
Host: inceptiondb.hola.cloud
Api-Key: $INCEPTIONDB_API_KEY
Api-Secret: $INCEPTIONDB_API_SECRET
{"filter": {"id": "alan"}, "patch": {"plan": "pro", "mrr": 120}}package main
import (
"fmt"
"io"
"net/http"
"os"
"encoding/json"
"strings"
)
func main() {
payload := map[string]any{"filter": map[string]any{"id": "alan"}, "patch": map[string]any{"mrr": 120, "plan": "pro"}}
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:patch", 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' => ['id' => 'alan'], 'patch' => ['mrr' => 120, 'plan' => 'pro']];
$body = json_encode($payload);
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => 'https://inceptiondb.hola.cloud/v1/databases/' . getenv('INCEPTIONDB_DATABASE') . '/collections/customers:patch',
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": {"id": "alan"}, "patch": {"mrr": 120, "plan": "pro"}}
body = json.dumps(payload)
response = requests.request(
"POST",
"https://inceptiondb.hola.cloud/v1/databases/" + os.environ["INCEPTIONDB_DATABASE"] + "/collections/customers:patch",
headers=headers,
data=body
)
print(response.text)
const payload = {"filter": {"id": "alan"}, "patch": {"mrr": 120, "plan": "pro"}};
const response = await fetch("https://inceptiondb.hola.cloud/v1/databases/" + process.env.INCEPTIONDB_DATABASE + "/collections/customers:patch", {
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": {"id": "alan"}, "patch": {"mrr": 120, "plan": "pro"}};
const response = await fetch("https://inceptiondb.hola.cloud/v1/databases/" + INCEPTIONDB_DATABASE + "/collections/customers:patch", {
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("id", "alan"), "patch", Map.of("mrr", 120, "plan", "pro"));
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:patch"))
.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":"alan","name":"Alan Turing","email":"alan@example.com","plan":"pro","country":"GB","mrr":120,"tags":["beta"],"address":{"city":"Manchester","zip":"M1"}}
7. Borra un documento
curl -X POST "https://inceptiondb.hola.cloud/v1/databases/$INCEPTIONDB_DATABASE/collections/customers:remove" \
-H "Api-Key: $INCEPTIONDB_API_KEY" \
-H "Api-Secret: $INCEPTIONDB_API_SECRET" \
-d '{"filter": {"id": "grace"}}'POST /v1/databases/$INCEPTIONDB_DATABASE/collections/customers:remove HTTP/1.1
Host: inceptiondb.hola.cloud
Api-Key: $INCEPTIONDB_API_KEY
Api-Secret: $INCEPTIONDB_API_SECRET
{"filter": {"id": "grace"}}package main
import (
"fmt"
"io"
"net/http"
"os"
"encoding/json"
"strings"
)
func main() {
payload := map[string]any{"filter": map[string]any{"id": "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:remove", 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' => ['id' => '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:remove',
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": {"id": "grace"}}
body = json.dumps(payload)
response = requests.request(
"POST",
"https://inceptiondb.hola.cloud/v1/databases/" + os.environ["INCEPTIONDB_DATABASE"] + "/collections/customers:remove",
headers=headers,
data=body
)
print(response.text)
const payload = {"filter": {"id": "grace"}};
const response = await fetch("https://inceptiondb.hola.cloud/v1/databases/" + process.env.INCEPTIONDB_DATABASE + "/collections/customers:remove", {
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": {"id": "grace"}};
const response = await fetch("https://inceptiondb.hola.cloud/v1/databases/" + INCEPTIONDB_DATABASE + "/collections/customers:remove", {
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("id", "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:remove"))
.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());
}
}La respuesta trae el documento borrado:
1{"id":"grace","name":"Grace Hopper","email":"grace@example.com","plan":"team","country":"US","mrr":480,"tags":["vip"],"address":{"city":"New York","zip":"10001"}}
Siguientes pasos
- Consultas: todos los operadores de filtro, paginación y exportaciones.
- Índices: búsquedas instantáneas por email, rangos por importe y búsqueda por palabras.
- Trabajando con datos: inserciones masivas, actualizar muchos documentos y errores.
- La consola muestra el código de cada acción que haces en ella: pulsa las bolas de la derecha de la pantalla.
Comentarios