Exercise: Create a New User

Practice creating a document in MongoDB collection through the Go API.

We'll cover the following

Problem statement

Creating a document is a fundamental operation while working on a MongoDB project. This exercise tests your knowledge of creating a new document.

Task

We have a database, shive-api, with a collection, user. Each document in this collection has the following attributes: ID, Name, Email, Password, and Age. The user model is already defined in the userModel.go file under:

package models


type User struct {
	ID            int 				 `json:"id"`
	Name          string             `json:"name"`
    Email         string             `json:"email"`
	Password      string             `json:"password"`
    Age           int                `json:"age"`
	  
}

For this exercise, you need to insert a new user as per the following table:

Get hands-on with 1200+ tech skills courses.