Search.../

queryGroups( )

Creates a query to retrieve a list of groups.

Description


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()

Syntax

function queryGroups(): GroupsQueryBuilder

queryGroups Parameters

This function does not take any parameters.

Returns

A GroupsQueryBuilder object that contains the refined query.

Return Type:

Was this helpful?

Query groups

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { groups } from 'wix-groups-backend';
3
4export const myQueryGroupsFunction = webMethod(Permissions.Anyone, () => {
5 return groups.queryGroups()
6 .find()
7 .then((results) => {
8 const items = results.items;
9 const firstItem = items[0];
10 const pageSize = results.pageSize;
11 const totalPages = results.totalPages;
12 const totalCount = results.totalCount;
13 const currentPage = results.currentPage();
14 const next = results.next();
15 const previous = results.prev();
16 const hasNext = results.hasNext();
17 const hasPrev = results.hasPrev();
18 const length = results.length;
19
20 return items;
21 })
22 .catch((error) => {
23 console.error(error);
24 });
25});
26
27/* Returns items:
28 * [
29 * {
30 * "_id": "83636377-b415-4ebe-ba41-df338c5ad6b7"
31 * "name": "My Group 1"
32 * "slug": "my-group-1"
33 * "description": "Welcome to the group! You can connect with other members, get updates and share videos."
34 * "privacyStatus": "PUBLIC"
35 * "coverImage": {
36 * "imageUrl": "wix:image://v1/zc0974e348009011fa9f2d29zc~mv2.jpg/pickles.jpg#originWidth=607&originHeight=670",
37 * "position": {
38 * "x": 500,
39 * "y": 500
40 * }
41 * }
42 * "memberCount": 83
43 * "settings": {
44 * "groupUpdatePostEnabled": true
45 * "membersCanApprove": false
46 * "membersCanInvite": true
47 * "showMemberList": true
48 * "welcomeMemberPostEnabled": true
49 * }
50 * "lastActivityDate": "Sun Sep 26 2021 08:23:23 GMT+0300"
51 * "_createdDate": "Tues January 22 2021 12:56:02 GMT+0300"
52 * "_updatedDate": "Fri October 2 2021 04:56:22 GMT+0300"
53 * "owner": "9ne8e9e1-d050-4c86-9684-e7f231600a34"
54 * },
55 * {
56 * "_id": "6ff5333-b477-4e9tt-ba4j-df338c5ad6221"
57 * "name": "My Group 2"
58 * "slug": "my-group-2"
59 * "description": "Welcome to the group! You can connect with other members, get updates and share videos."
60 * "privacyStatus": "PRIVATE"
61 * "coverImage": {
62 * "imageUrl": "wix:image://v1/q224e348009011fa9f2d29kk099~mv2.jpg/maple.jpg#originWidth=465&originHeight=448",
63 * "position": {
64 * "x": 24,
65 * "y": 34
66 * }
67 * }
68 * "memberTitle": "Friends"
69 * "memberCount": 68
70 * "settings": {
71 * "groupUpdatePostEnabled": true
72 * "membersCanApprove": true
73 * "membersCanInvite": true
74 * "showMemberList": false
75 * "welcomeMemberPostEnabled": true
76 * }
77 * "lastActivityDate": "Thurs Nov 12 2020 11:13:03 GMT+0300"
78 * "_createdDate": "Wed May 14 2020 10:05:20 GMT+0300"
79 * "_updatedDate": "Sun June 7 2020 09:07:33 GMT+0300"
80 * "owner": "abe5e4e1-d950-4c46-8884-e7f231600d67"
81 * }
82 * ]
83 */