ACM-VIT / SDG-Backend

0 stars 0 forks source link

Check for Unique Seller Name #1

Open mahendra785 opened 1 month ago

mahendra785 commented 1 month ago

Ensure that when a new seller is registering, their name is unique. If the seller name is already taken, prevent the registration and show a message indicating that the seller name is unavailable.

D-Vspec commented 1 month ago

Check for Unique Seller Name

Objective

Ensure that when a new seller is registering, their name is unique. If the seller name is already taken, prevent the registration and show a message indicating that the seller name is unavailable.

Steps

1. Define the Seller Schema with a Unique Constraint

Mongoose Schema Example:


const mongoose = require('mongoose');

const sellerSchema = new mongoose.Schema({
    name: {
        type: String,
        required: true,
        unique: true  // Ensure the name is unique in the database
    },
    email: {
        type: String,
        required: true,
        unique: true
    },
    // Add other fields as needed
});

const Seller = mongoose.model('Seller', sellerSchema);

module.exports = Seller;