Delete

Overview of collection delete methods

delete
Delete One

https://api.codemash.io/:version/db/:collectionName
Deletes a particular record from a collection.
Request
Response
Request
Path Parameters
version
required
string
A version of the API endpoint.
collectionName
required
string
The name of the collection to delete a record from.
Headers
Authorization
required
string
Secret API key which belongs to your project or user. Not required if using cookies with a session ID.
x-cm-projectid
required
string
Your project's ID. Can be passed as a query parameter.
Body Parameters
filter
required
string
Filter document. Used to find the record to delete. More about filters follow the example below.
Response
200: OK
Returns a delete result.
{
"result": {
"isAcknowledged": true,
"deletedCount": 1
}
}
.NET
Node
PHP
.NET
var client = new CodeMashClient(apiKey, projectId);
var service = new CodeMashRepository<Person>(client);
await service.DeleteOneAsync(
x => x.Id == "record_id"
);

Check the information about entities on how your filter parameters are mapped.

Node
import { db } from 'codemash';
export async function deleteEmployee(id) {
return await db.deleteRecord('employees', { _id: id });
}
PHP
use Codemash\CodemashClient;
use Codemash\CodemashDb;
class CodemashService
{
protected CodemashDb $codemashDb;
protected string $collectionName = '{YOUR_COLLECTION_NAME}';
public function __construct()
{
$secretKey = '{YOUR_SECRET_KEY}';
$projectId = '{YOUR_PROJECT_ID}';
$client = new CodemashClient($secretKey, $projectId);
$this->codemashDb = new CodemashDb($client);
}
public function deleteOne()
{
$responseData = $this->codemashDb->deleteOneWithFilter([
'collectionName' => 'employees',
'filter' => [
'email' => '[email protected]',
],
]);
}
}

Check the docs on how to form filters.

delete
Delete Many

https://api.codemash.io/:version/db/:collectionName/bulk
Deletes multiple records from a collection.
Request
Response
Request
Path Parameters
version
required
string
A version of the API endpoint.
collectionName
required
string
The name of the collection to delete records from.
Headers
Authorization
required
string
Secret API key which belongs to your project or user. Not required if using cookies with a session ID.
x-cm-projectid
required
string
Your project's ID. Can be passed as a query parameter.
Body Parameters
filter
required
string
Filter document. Used to find records to delete. More about filters follow a link below.
Response
200: OK
Returns a delete result.
{
"result": {
"isAcknowledged": true,
"deletedCount": 5
}
}
.NET
Node
PHP
.NET
var client = new CodeMashClient(apiKey, projectId);
var service = new CodeMashRepository<Person>(client);
await service.DeleteManyAsync(
x => x.Name == "John"
);

Check the information about entities on how your filter parameters are mapped.

Node
PHP
use Codemash\CodemashClient;
use Codemash\CodemashDb;
class CodemashService
{
protected CodemashDb $codemashDb;
protected string $collectionName = '{YOUR_COLLECTION_NAME}';
public function __construct()
{
$secretKey = '{YOUR_SECRET_KEY}';
$projectId = '{YOUR_PROJECT_ID}';
$client = new CodemashClient($secretKey, $projectId);
$this->codemashDb = new CodemashDb($client);
}
public function deleteMany()
{
$client = new CodemashClient('{YOUR_SECRET_KEY}', '{YOUR_PROJECT_ID}');
$codemashDb = new CodemashDb($client);
$responseData = $this->codemashDb->deleteMany([
'collectionName' => 'employees',
'filter' => [
'address' => 'New York',
],
]);
}
}

Check the docs on how to form filters.