S
S
stas_mihailov2020-04-20 14:46:42
MongoDB
stas_mihailov, 2020-04-20 14:46:42

Checking for the completion of one of the fields in the mongo model?

Hai! There is the following model:

const mongoose = require("mongoose");

const UserSchema = new mongoose.Schema({
  name: {
    type: String,
  },
  email: {
    type: String,
    required: true,
    unique: true
  },
  phone: {
    type: String,
    required: true,
    unique: true
  },
  password: {
    type: String,
    required: true
  },
  avatar: {
    type: String
  },
  date: {
    type: Date,
    default: Date.now
  }
});

module.exports = User = mongoose.model("user", UserSchema);


When registering, the user chooses with what he wants to register - email or phone ...
How to describe the fields in the model so that only the filled field is validated during verification?
If you entered the phone, then register using it, or if you entered email, then by email ...

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question