Buscar documentos
POST /v1/databases/{databaseId}/collections/{collection}:find · API key
Petición: JSON, Content-Type: application/json · Respuesta: JSONL, o 204 No Content con el cuerpo vacío
| Campo del cuerpo | Por defecto | Significado |
|---|---|---|
filter |
{} |
Condiciones; ver Consultas. |
limit |
1 |
Número máximo de documentos. -1 los devuelve todos. |
skip |
0 |
Documentos que coinciden que se saltan primero. |
index |
ninguno | Nombre de un índice con el que responder. |
value |
Valor a buscar, con un índice map. |
|
from, to |
Límites del rango, con un índice btree. Ejemplo: {"mrr": 100}. |
|
reverse |
false |
Orden descendente, con un índice btree. |
match |
Palabras a buscar, con un índice fts. |
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" \
-H "Content-Type: application/json" \
-d '{"filter": {"plan": {"$in": ["pro", "team"]}}, "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
Content-Type: application/json
{"filter": {"plan": {"$in": ["pro", "team"]}}, "limit": 10}// Go 1.21+, standard library only. Save as main.go and run: go run main.go
package main
import (
"fmt"
"io"
"net/http"
"os"
"encoding/json"
"strings"
)
func main() {
payload := map[string]any{"filter": map[string]any{"plan": map[string]any{"$in": []any{"pro", "team"}}}, "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"))
req.Header.Set("Content-Type", "application/json")
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(resp.Status)
fmt.Println(string(responseBody))
}
<?php
// PHP 8+ with the curl extension. Save as example.php and run: php example.php
$payload = ['filter' => ['plan' => ['$in' => ['pro', 'team']]], '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'),
'Content-Type: application/json',
],
]);
$response = curl_exec($ch);
if ($response === false) {
throw new Exception(curl_error($ch));
}
echo curl_getinfo($ch, CURLINFO_RESPONSE_CODE), "\n", $response, "\n";
curl_close($ch);
# Python 3.8+. Install: pip install requests. Save as example.py and run: python example.py
import os
import requests
headers = {
"Api-Key": os.environ["INCEPTIONDB_API_KEY"],
"Api-Secret": os.environ["INCEPTIONDB_API_SECRET"],
"Content-Type": "application/json",
}
payload = {"filter": {"plan": {"$in": ["pro", "team"]}}, "limit": 10}
response = requests.request(
"POST",
"https://inceptiondb.hola.cloud/v1/databases/" + os.environ["INCEPTIONDB_DATABASE"] + "/collections/customers:find",
headers=headers,
json=payload
)
print(response.status_code)
print(response.text)
// Node.js 18+. Save as example.mjs and run: node example.mjs
const payload = {"filter": {"plan": {"$in": ["pro", "team"]}}, "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,
"Content-Type": "application/json"
},
body: JSON.stringify(payload)
});
console.log(response.status);
console.log(await response.text());
// Java 17+, standard library only. Save as Main.java and run: java Main.java
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 body = """
{"filter": {"plan": {"$in": ["pro", "team"]}}, "limit": 10}
""";
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"))
.header("Content-Type", "application/json")
.build();
var response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode());
System.out.println(response.body());
}
}Respuesta 200 OK, los documentos como JSON Lines. 204 No Content cuando nada coincide.
1{"id":"ada","name":"Ada Lovelace","plan":"pro","mrr":120}
Operadores: $eq, $ne, $gt, $ge, $lt, $le, $in, $nin, $contains, $and, $or.
$gtey$lteno existen: usa$gey$le. Un operador desconocido no se notifica como error: el filtro no coincide con nada y la respuesta es204 No Content.
Comentarios