find

find countries

lets add getCountries functions:

Example
    
  const getCountriesValidator = () => {
    return object({
      set: object({
        page: number(),
        limit: number(),
      }),
      get: coreApp.schemas.selectStruct("country", 1),
    });
  };
  const getCountries: ActFn = async (body) => {
    let {
      set: { page, limit },
      get,
    } = body.details;
    page = page || 1;
    limit = limit || 50;
    const skip = limit * (page - 1);
    

return await countries .find({ projection: get, filters: {} }) .skip(skip) .limit(limit) .toArray();

}; coreApp.acts.setAct({ schema: "country", actName: "getCountries", validator: getCountriesValidator(), fn: getCountries, });

find functions accept three inputs:

The code

So this is all the code we've written so far (You can also see and download this code from here):

Return Of Example:
    
      {
        body: [
          {
            _id: 659fda257b94d4cdfed11dec,
            name: Kiribati,
            population: 68092328,
            abb: AIA
          },
          {
            _id: 659fda267b94d4cdfed11ded,
            name: Aruba,
            population: 31408054,
            abb: BHS
          }
        ],
        success: true
      }