Find One

Gets record by specified database unique id or filter.

Finds one database record. You can pass projection to return record fields you care about. Also, you can include referenced collections to have all that information in one place.

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.

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

Find One (by using a filter)

GET https://api.codemash.io/:version/db/:collectionName/findOne

Gets a record by using a filter. This endpoint accepts GET and POST methods.

Path Parameters

NameTypeDescription

version

string

A version of the API endpoint.

collectionName

string

The name of the collection to get a record from.

Query Parameters

NameTypeDescription

filter

string

Filter document. This allows you to find a record by a custom filter. More about filters follow the link below.

referencedFields

array

Fields to left join. More about referencing fields follow the link below.

addReferencesFirst

boolean

If set to true, left joins first before applying other processing to main records. More about referencing fields follow the link below.

cultureCode

string

Language code. If your record has translatable fields, those fields will only include this specified language. If not provided, will take language from the Accept-Language header.

projection

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

boolean

If set to true, includes your collection details in the response.

excludeCulture

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.

Headers

NameTypeDescription

Authorization

string

Secret API key which belongs to your project or user. Not required if using cookies with a session ID.

x-cm-projectid

string

Your project's ID. Can be passed as a query parameter.

{
    "result": "{ '_id': '5e37136bf59f3a3f940b99a4', 'name': 'John' }",
    "schema": null,
}
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.

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

Last updated