findOne
find a country
lets add getCountry functions:
Example
const getCountryValidator = () => {
return object({
set: object({
countryId: objectIdValidation,
}),
get: coreApp.schemas.selectStruct("country", {
citiesByPopulation: 1,
users: 1,
capital: 1,
}),
});
};
const getCountry: ActFn = async (body) => {
const {
set: { countryId },
get,
} = body.details;
return await countries
.findOne({
filters: { _id: new ObjectId(countryId) },
projection: get,
});
};
coreApp.acts.setAct({
schema: "country",
actName: "getCountry",
validator: getCountryValidator(),
fn: getCountry,
});
findOne
functions accept three inputs:
filters
which is mongodb findOne query operationprojection
which is mongodb projection operation- and optional
option
which is mongodb findOption
You can also read mongodb findOne
section for more information.
Return Of Example:
{
body:
{
_id: 659fda257b94d4cdfed11dec,
name: Kiribati,
population: 68092328,
abb: AIA
},
success: true
}