Data Models

The "User" model represents a user in your Ecommerce script. It stores information about users, including their personal details and login credentials.

Schema

The "User" model schema includes the following fields:


import mongoose from "mongoose";


const UserSchema = new mongoose.Schema(
  {
    firstName: {
      type: String,
      required: [true, "Please provide a First name."],
      maxlength: [20, "First Name cannot be more than 60 characters"],
    },
    lastName: {
      type: String,
      required: [true, "Please provide a Last name."],
      maxlength: [20, "Last Name cannot be more than 60 characters"],
    },
    fullName: {
      type: String,
    },
    avatar: {
      type: Object,
    },
    gender: {
      type: String,
    },
    phone: {
      type: String,
      required: [true, "Please provide a Phone Number."],
      maxlength: [20, "Phone cannot be more than 60 characters"],
    },
    email: {
      type: String,
      unique: true,
      required: "Email address is required",
    },
    addresses: {
      type: Array,
    },
    password: {
      type: String,
      select: false,
      required: [true, "Please enter Password."],
    },
    status: {
      type: String,
    },
    about: {
      type: String,
    },
    joined: {
      type: Date,
      default: Date.now(),
    },
  },
  { timestamps: true }
);

export default mongoose.models.User || mongoose.model("User", UserSchema);