queryGroups( )


Creates a query to retrieve a list of groups.

Note: For SECRET groups, only site admins, group admins, and group members can query groups and their content. However, if the suppressAuth option is set to true, all permissions are overwritten, and all site members (including non-group members) can query groups and their content.

The queryGroups() function builds a query to retrieve a list of all groups, and returns a GroupsQueryBuilder object.

The returned object contains the query definition which is typically used to run the query using the find() function.

You can refine the query by chaining GroupsQueryBuilder functions onto the query. GroupsQueryBuilder functions enable you to sort, filter, and control the results that queryGroups() returns.

queryGroups() runs with these GroupsQueryBuilder defaults, which you can override:

The following GroupsQueryBuilder functions are supported for queryGroups(). For a full description of the Groups object, see the object returned for the items property in GroupsQueryResult.

PropertySupported Filters & Sorting
nameeq(), ne(), startsWith(), endsWith(), contains(),hasSome(), ascending(), descending(), or()
_createdDateascending(), descending()
memberCountascending(), descending()
lastActivityDateascending(), descending()
Method Declaration
Copy
function queryGroups(): GroupsQueryBuilder;
Request
This method does not take any parameters
Returns
Return Type:GroupsQueryBuilder
Query groups
JavaScript
import { Permissions, webMethod } from "wix-web-module"; import { groups } from "wix-groups-backend"; export const myQueryGroupsFunction = webMethod(Permissions.Anyone, () => { return groups .queryGroups() .find() .then((results) => { const items = results.items; const firstItem = items[0]; const pageSize = results.pageSize; const totalPages = results.totalPages; const totalCount = results.totalCount; const currentPage = results.currentPage(); const next = results.next(); const previous = results.prev(); const hasNext = results.hasNext(); const hasPrev = results.hasPrev(); const length = results.length; return items; }) .catch((error) => { console.error(error); }); }); /* Returns items: * [ * { * "_id": "83636377-b415-4ebe-ba41-df338c5ad6b7" * "name": "My Group 1" * "slug": "my-group-1" * "description": "Welcome to the group! You can connect with other members, get updates and share videos." * "privacyStatus": "PUBLIC" * "coverImage": { * "imageUrl": "wix:image://v1/zc0974e348009011fa9f2d29zc~mv2.jpg/pickles.jpg#originWidth=607&originHeight=670", * "position": { * "x": 500, * "y": 500 * } * } * "memberCount": 83 * "settings": { * "groupUpdatePostEnabled": true * "membersCanApprove": false * "membersCanInvite": true * "showMemberList": true * "welcomeMemberPostEnabled": true * } * "lastActivityDate": "Sun Sep 26 2021 08:23:23 GMT+0300" * "_createdDate": "Tues January 22 2021 12:56:02 GMT+0300" * "_updatedDate": "Fri October 2 2021 04:56:22 GMT+0300" * "owner": "9ne8e9e1-d050-4c86-9684-e7f231600a34" * }, * { * "_id": "6ff5333-b477-4e9tt-ba4j-df338c5ad6221" * "name": "My Group 2" * "slug": "my-group-2" * "description": "Welcome to the group! You can connect with other members, get updates and share videos." * "privacyStatus": "PRIVATE" * "coverImage": { * "imageUrl": "wix:image://v1/q224e348009011fa9f2d29kk099~mv2.jpg/maple.jpg#originWidth=465&originHeight=448", * "position": { * "x": 24, * "y": 34 * } * } * "memberTitle": "Friends" * "memberCount": 68 * "settings": { * "groupUpdatePostEnabled": true * "membersCanApprove": true * "membersCanInvite": true * "showMemberList": false * "welcomeMemberPostEnabled": true * } * "lastActivityDate": "Thurs Nov 12 2020 11:13:03 GMT+0300" * "_createdDate": "Wed May 14 2020 10:05:20 GMT+0300" * "_updatedDate": "Sun June 7 2020 09:07:33 GMT+0300" * "owner": "abe5e4e1-d950-4c46-8884-e7f231600d67" * } * ] */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?