Get Free Trial
API reference
Table of contents

getMembers

getMembers(mongoDBInstance: Db instance, index: String, fieldInfo: Object, page: Object)

[starting from version: 2.8]

This API call allows getting all members of the field from a MongoDB database. Used in the handler of the Flexmonster /members request. The getMembers method is a part of the Flexmonster MongoDB Connector API.

Parameters

  • mongoDBInstanceDb instance. The instance of the needed MongoDB database.
  • index – String. The collection’s name. The index is sent in the body of the Flexmonster request.
  • fieldInfo – Object. Has the following properties:
    • fieldField Object. The field whose members should be sent in the response. The field is sent in the body of the Flexmonster request.
    • filterFilter Group Object. Filters that should be applied to members. The filter is sent in the body of the Flexmonster request when multilevel hierarchies are configured in the component.
  • page – Object. Has the following properties:
    • pageNumber – Number. Page number. Used to load members by parts. Starts from 0. pageNumber is sent in the body of the Flexmonster request.
    • pageToken – String. A key calculated on the server that defines which part of the data should be loaded next. pageToken is sent in the body of the Flexmonster request.

Returns

An array of objects, which contains all the members. The response format is the same as in the /members request.

Examples

1) Handling the /members request using the getMembers method:

mongo.post("/members", async (req, res) => {
try {
        const result = await MongoDataAPI.getMembers(
mongoDBInstance,
req.body.index,
{ req.body.field },
{pageNumber: req.body.page, pageToken: req.body.pageToken}
);
        res.json(result);
    } catch (err) { }
});

2) Handling the /members request when multilevel hierarchies are configured in the component:

mongo.post("/members", async (req, res) => {
   try {
        const result = await MongoDataAPI.getMembers(
           mongoDBInstance,
           req.body.index, 
           {field: req.body.field, filter: req.body.filter},
           {pageNumber: req.body.page, pageToken: req.body.pageToken}
       );
        res.json(result);
    } catch (err) { }
});

See also

getSchema
getSelectResult