When you execute a query with the find()
function, it returns a Promise that resolves to a GroupsQueryResult
object.
This object contains the items that match the query, information about the
query itself, and functions for paging through the query results.
Returns the index of the current results page number.
The currentPage
is a zero-based index of the current page of results.
The page size is defined by the limit()
function, can be retrieved using the pageSize
property, and
navigating through pages is done with the prev()
and
next()
functions.
The currentPage
property returns undefined
if the query returned no results.
let resultPage = results.currentPage; // 0
Returns the items that match the query.
The current page of groups retrieved by the query.
Note: When no items match the query, the items array is empty.
To paginate your query results, use the GroupsQueryResult
pagination properties and functions.
import { Permissions, webMethod } from "wix-web-module";
import { groups } from "wix-groups-backend";
export const getQueryResultItems = webMethod(Permissions.Anyone, async () => {
try {
const options = {
suppressAuth: true,
};
const results = await groups.queryGroups().limit(3).find(options);
if (results.items.length > 0) {
return results.items;
} else {
console.log("No items found");
}
} catch (error) {
console.error(error);
}
});
/* items:
* [
* {
* "coverImage":{
* "imageUrl": "wix:image://v1/jb9074e348009011fa9f2dzj0jn~mv2.jpg/nutmeg.jpg#originWidth=800&originHeight=720",
* "position": {
* "x": 200,
* "y": 350
* }
* },
* "_createdDate":"2021-10-06T09:33:16.000Z",
* "description":"Welcome to the group! You can connect with other members, get updates and share videos.",
* "_id":"7e75dade-5f62-4eb4-b861-fa35b36d1f8d",
* "lastActivityDate":"2021-10-06T09:33:16.000Z",
* "memberCount": 37,
* "memberTitle":"Members",
* "name":"Group1",
* "owner":"937cd3db-e9be-4980-93c1-a6d767a11050",
* "privacyStatus":"PUBLIC",
* "settings":{
* "groupUpdatePostEnabled": true,
* "membersCanApprove": false,
* "membersCanInvite": true,
* "showMemberList": true,
* "welcomeMemberPostEnabled": true
* },
* "slug":"group1",
* "_updatedDate": "2021-10-06T09:33:18.000Z"
* },
* "_id":"7e75dade-5f62-4eb4-b861-fa35b36d1f8d",
* "rejectionReason":"undefined",
* "status":"PENDING"
* },
* {
* "coverImage":{
* "imageUrl": "wix:image://v1/vcc6074e348009011fa9f2d29kk7~mv2.jpg/maple.jpg#originWidth=999&originHeight=240",
* "position": {
* "x": 20,
* "y": 35
* }
* },
* "_createdDate":"2021-09-04T09:31:11.000Z",
* "description":"Welcome to the group! You can connect with other members, get updates and share videos.",
* "_id":"50ba513d-e7e4-4970-9c69-deb25b047436",
* "lastActivityDate":2021-09-04T09:31:11.000Z",
* "memberCount": 102,
* "memberTitle":"Friends",
* "name":"Group2",
* "owner":"937cd3db-e9be-4980-93c1-a6d767a11050",
* "privacyStatus":"PUBLIC",
* "settings":{
* "groupUpdatePostEnabled": true,
* "membersCanApprove": false,
* "membersCanInvite": true,
* "showMemberList": true,
* "welcomeMemberPostEnabled": true
* },
* "slug":"group2",
* "_updatedDate": "2021-09-04T09:31:11.000Z"
* },
* "_id":"50ba513d-e7e4-4970-9c69-deb25b047436",
* "rejectionReason":"undefined",
* "status":"APPROVED"
* },
* {
* "coverImage":{
* "imageUrl": "wix:image://v1/ff9074e348009011fa9f2d2961b~mv2.jpg/oak.jpg#originWidth=400&originHeight=900",
* "position": {
* "x": 20,
* "y": 325
* }
* },
* "_createdDate":"2021-03-12T09:24:16.000Z",
* "description":"Welcome to the group! You can connect with other members, get updates and share videos.",
* "_id":"7e75dade-5f62-4eb4-b861-fa35b36d1f8d",
* "lastActivityDate":"2021-08-12T09:24:16.000Z",
* "memberCount": 8,
* "memberTitle":"Colleagues",
* "name":"Group3",
* "owner":"937cd3db-e9be-4980-93c1-a6d767a11050",
* "privacyStatus":"PUBLIC",
* "settings":{
* "groupUpdatePostEnabled": true,
* "membersCanApprove": false,
* "membersCanInvite": true,
* "showMemberList": true,
* "welcomeMemberPostEnabled": true
* },
* "slug":"group3",
* "_updatedDate":"2021-08-12T09:24:16.000Z"
* }
* ]
*/
let resultLength = results.length; // 20