Home > Back-end >  How to make a variable unique?
How to make a variable unique?

Time:11-28

I want to have the flight number variable unique. By unique, I mean it shouldn't be the same like another one that has been created before.

const flightSchema = new Schema ({ FlightNumber: { type: String, required: true, }, DepartureTime: { type: Date, required: true } }}

CodePudding user response:

Add unique: true, like FlightNumber: { type: String, required: true, unique: true }

CodePudding user response:

add unique: true

I hope it helps you

https://masteringjs.io/tutorials/mongoose/unique

  • Related