Find One

Overview of collection find one methods

get
Find One (by ID)

https://api.codemash.io/:version/db/:collectionName/:id
Gets a record by its ID. This endpoint accepts GET and POST methods.
Request
Response
Request
Path Parameters
version
required
string
A version of API endpoint.
collectionName
required
string
The name of collection to get a record from.
id
required
string
ID of a record to get.
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.
Query Parameters
referencedFields
optional
array
Fields to left join. More about referencing fields follow the link below.
addReferencesFirst
optional
boolean
If set to true, left joins before applying other processing to main records. More about referencing fields follow the link below.
cultureCode
optional
string
Language code. If your record has translatable fields, those fields will only include this specified language. If not provided, will take language from Accept-Language header.
projection
optional
string
Projection document. This allows you to specify what fields to return decreasing the amount of data transferred. More about projections follow the link below.
includeSchema
optional
boolean
If set to true, Includes your collection details in response.
excludeCulture
optional
boolean
Culture code or Accept-Language header will be used for translatable fields. If you want to get values in all languages, set this as true.
Response
200: OK
Returns a single record matched by ID. Here singular quotes are used to avoid escaping double quotes.
{
"result": "{ '_id': '5e37136bf59f3a3f940b99a4', 'name': 'John' }",
"schema": null,
}
.NET
Node
.NET
var client = new CodeMashClient(apiKey, projectId);
var service = new CodeMashRepository<Person>(client);
var person = await service.FindOneByIdAsync(
"{RECORD_ID}",
new DatabaseFindOneOptions()
);

Check the docs about entities on how the response record is deserialized into your class object.

Node
import { db } from 'codemash';
export async function getEmployeeDetails(id) {
const response = await db.getRecord('employees', id);
return response;
}

Check the docs on how to form projections. Check the docs on how to use references.

get
Find One (by filter)

https://api.codemash.io/:version/db/:collectionName/findOne
Gets a record by filter. This endpoint accepts GET and POST methods.
Request
Response
Request
Path Parameters
version
required
string
A version of API endpoint.
collectionName
required
string
The name of collection to get a record from.
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.
Query Parameters
filter
required
string
Filter document. This allows you to find a record by a custom filter. More about filters follow the link below.
referencedFields
optional
array
Fields to left join. More about referencing fields follow the link below.
addReferencesFirst
optional
boolean
If set to true, left joins first before applying other processing to main records. More about referencing fields follow the link below.
cultureCode
optional
string
Language code. If your record has translatable fields, those fields will only include this specified language. If not provided, will take language from Accept-Language header.
projection
optional
string
Projection document. This allows you to specify what fields to return decreasing the amount of data transferred. More about projections follow the link below.
includeSchema
optional
boolean
If set to true, includes your collection details in response.
excludeCulture
optional
boolean
Culture code or Accept-Language header will be used for translatable fields. If you want to get values in all languages, set this as true.
Response
200: OK
Returns a single record matched by a filter. Here singular quotes are used to avoid escaping double quotes.
{
"result": "{ '_id': '5e37136bf59f3a3f940b99a4', 'name': 'John' }",
"schema": null,
}
.NET
Node
.NET
var client = new CodeMashClient(apiKey, projectId);
var service = new CodeMashRepository<Person>(client);
var person = await service.FindOneAsync(
x => x.Id == "{RECORD_ID}",
new DatabaseFindOneOptions()
);

Check the docs about entities on how the response record is deserialized into your class object.

Node
import { db } from 'codemash';
export async function getEmployeeByUserId(id) {
const filter = { userId : id };
return await db.getRecordWithFilter(collectionName, filter, null);
}

Check the docs on how to form projections, filters. Check the docs on how to use references.