Update

Overview of collection update methods

put
Replace One

https://api.codemash.io/:version/db/:collectionName/replaceOne
Replaces a record in collection.
Request
Response
Request
Path Parameters
version
required
string
A version of API endpoint.
collectionName
required
string
The name of collection to replace record in.
Headers
Authorization
required
string
Secret API key which belongs to your project or user. Not required if using cookies with session ID.
x-cm-projectid
required
string
Your project's ID. Can be passed as query parameter.
Body Parameters
filter
required
string
Filter document. Used to find the record to replace. More about filters follow the link below.
document
required
string
A replacement for a found record.
bypassDocumentValidation
optional
boolean
If set to true, document will not be validated against the schema.
waitForFileUpload
optional
boolean
If set to true, waits for files to be uploaded before returning from endpoint.
isUpsert
optional
boolean
If set to true, inserts a record if it's not found.
Response
200: OK
Returns a replace one result.
{
"result": {
"isAcknowledged": true,
"isModifiedCountAvailable": true,
"matchedCount": 1,
"modifiedCount": 1,
"upsertedId": 0
}
}
.NET
Node
.NET
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.

Node
import { db } from 'codemash';
export async function replaceEmployeeInformation(id, employee) {
return await db.replaceRecord('employees', { _id: id }, employee);
}

Check the docs on how to form filters.

patch
Update One

https://api.codemash.io/:version/db/:collectionName
Updates specified fields in a record.
Request
Response
Request
Path Parameters
version
required
string
A version of API endpoint.
collectionName
required
string
The name of collection to replace record in.
Headers
Authorization
required
string
Secret API key which belongs to your project or user. Not required if using cookies with session ID.
x-cm-projectid
required
string
Your project's ID. Can be passed as query parameter.
Body Parameters
filter
required
string
Filter document. Used to find the record to replace. More about filters follow the link below.
update
required
string
Update document. Used to specify how to update the record. More about update documents follow the link below.
bypassDocumentValidation
optional
boolean
If set to true, document will not be validated against the schema.
waitForFileUpload
optional
boolean
If set to true, waits for files to be uploaded before returning from endpoint.
isUpsert
optional
boolean
If set to true, inserts a record if it's not found.
Response
200: OK
Returns an update result.
{
"result": {
"isAcknowledged": true,
"isModifiedCountAvailable": true,
"matchedCount": 1,
"modifiedCount": 1,
"upsertedId": 0
}
}
.NET
Node
.NET
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.

Node
import { db } from 'codemash';
export async function activateEmployee(id) {
return await db.updateRecord('employees',
{ _id: id },
{ $set: { 'is_active' : 1 }});
}

Check the docs on how to form filters.