Fetch All Users
Learn how to retrieve all the data from MongoDB collection.
Fetching all the platform users
Only admin users are able to view every user in the database. The admin can utilize this feature to see who has registered for the platform and how many users there are overall. This request provides details about each user in the database’s user collection.
Setting up the controller
We need to create a new controller function, GetUsers()
. This route is protected by the authentication middleware, which checks to ensure that only authenticated users can access it. Next, we write a check to see the user_type
of the user trying to access this data. If the user_type
is not equal to ADMIN
, we’ll deny this user entry. Next, we need to search the user collection for all the users who have signed up and the total number of registered users. In the userController.go
file, we should have a function like this below:
Get hands-on with 1400+ tech skills courses.