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 /deleteOne and /deleteMany endpoints via the REST API.

Parameters for Delete Operations

deleteOne Operation

The deleteOne operation is used to delete a single document in a collection based on a filter. If multiple documents match the filter, only the first matching document will be deleted.

Endpoint

To delete a single document, use the following endpoint:

{collection_url}/deleteOne

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

Example Python Code for deleteOne

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

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"
 
# DeleteOne URL
url = f"{collection_url}/deleteOne"
 
# 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 request
response = requests.post(url, json=data, headers=headers)
 
# Print the response
print(response.json())

deleteOne Response

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

{
  "status": "success",
  "deleted_count": 1
}

deleteMany Operation

The deleteMany operation is used to delete multiple documents in a collection based on a filter.

Endpoint

To delete multiple documents, use the following endpoint:

{collection_url}/deleteMany

Where {collection_url} is the full collection URL.

Example Python Code for deleteMany

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

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"
 
# DeleteMany URL
url = f"{collection_url}/deleteMany"
 
# Filter to match the documents to delete
filter = {
    "age": {"$gt": 30}
}
 
# Request body
data = {
    "filter": filter
}
 
# Headers with API Key
headers = {
    "Authorization": f"Bearer {ONENODE_API_KEY}",
    "Content-Type": "application/json"
}
 
# Sending the request
response = requests.post(url, json=data, headers=headers)
 
# Print the response
print(response.json())

deleteMany Response

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

{
  "status": "success",
  "deleted_count": 5
}

Important Notes