Document
Delete

Delete

OneNode DB supports deletion of documents using operations similar to MongoDB. You can delete one or multiple documents by specifying filters. This guide explains how to use the /document endpoint via the REST API to perform delete operations.

Parameters for Delete Operations

ParameterDescription
filterA query object to match the documents to delete. This works the same way as MongoDB filters, where you specify conditions to find the documents that need to be deleted. For more details, refer to the official MongoDB documentation on query filters (opens in a new tab).

Delete Operation

The delete operation is used to delete one or multiple documents in a collection based on a filter. The /document endpoint is used with a DELETE request to perform both single and multiple document deletions.

Endpoint

To delete documents, use the following endpoint:

{collection_url}/document

Where {collection_url} is the full collection URL that includes your db_id and collection_name.

Example Python Code for delete

Here’s how you can delete documents using Python, by applying a filter:

Python
import os
import requests
 
# API Key and Collection URL
ONENODE_API_KEY = os.getenv('ONENODE_API_KEY')
collection_url = "https://api.onenode.ai/v1/db/123abc/collection/my_collection"
 
# Document URL for Delete
url = f"{collection_url}/document"
 
# Filter to match the document(s) to delete
filter = {
    "email": "johndoe@example.com"
}
 
# Request body
data = {
    "filter": filter
}
 
# Headers with API Key
headers = {
    "Authorization": f"Bearer {ONENODE_API_KEY}",
    "Content-Type": "application/json"
}
 
# Sending the DELETE request
response = requests.delete(url, json=data, headers=headers)
 
# Print the response
print(response.json())

Delete Response

A successful delete operation will return a JSON response indicating the number of deleted documents:

{
  "deleted_count": 1
}

Important Notes