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