Borrar documentos

POST /v1/databases/{databaseId}/collections/{collection}:remove · API key

Campo del cuerpo Por defecto Significado
filter {} Qué documentos; misma sintaxis que :find.
limit 1 Número máximo de documentos a borrar. -1 borra todos los que coinciden.
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": "alan"}}'
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": "alan"}}
package main

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

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

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": "alan"}};

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", "alan"));
        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());
    }
}

Respuesta 200 OK, los documentos borrados como JSON Lines:

1{"id":"alan","name":"Alan Turing","plan":"free","mrr":0}

Comentarios

Deja un comentario