Update
Overview of collection update methods
put
https://api.codemash.io
/:version/db/:collectionName/replaceOne
Replace One
.NET
Node
PHP
var client = new CodeMashClient(apiKey, projectId);
var service = new CodeMashRepository<Person>(client);
​
var person = new Person { Id = "record_id" Name = "Peter" };
​
await service.ReplaceOneRequest(
x => x.Id == "record_id",
person,
new DatabaseReplaceOneOptions()
);
Check the information about entities on how your class objects are serialized.
import { db } from 'codemash';
​
export async function replaceEmployeeInformation(id, employee) {
return await db.replaceRecord('employees', { _id: id }, employee);
}
​
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 replaceOne()
{
$responseData = $this->codemashDb->replaceOne([
'collectionName' => 'employees',
'filter' => [
'name' => 'Peter',
'email' => '[email protected]',
],
'document' => [
'name' => 'Peter Smith',
'email' => '[email protected]',
'address' => 'Miami',
],
]);
}
}
Check the docs on how to form filters.
patch
https://api.codemash.io
/:version/db/:collectionName
Update One
.NET
Node
PHP
var client = new CodeMashClient(apiKey, projectId);
var service = new CodeMashRepository<Person>(client);
​
var person = new Person { Id = "record_id" Name = "Peter" };
var updateDefinition = Builders<Person>.Update.Set(x => x.Name , "Peter II");
​
await service.UpdateOneRequest(
x => x.Id == person.Id,
updateDefinition,
new DatabaseUpdateOneOptions()
);
Check the information about entities on how your class objects are serialized.
import { db } from 'codemash';
​
export async function activateEmployee(id) {
​
return await db.updateRecord('employees',
{ _id: id },
{ $set: { 'is_active' : 1 }});
}
​
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 updateOne()
{
$responseData = $this->codemashDb->updateOne([
'collectionName' => 'employees',
'id' => '{EMPLOYEE_ID}',
'update' => [
'$set' => [
'address' => 'Chicago',
],
],
]);
}
}
Check the docs on how to form filters.
Last modified 1yr ago
Copy link
On this page
put
Replace One
patch
Update One