louischatriot / nedb

The JavaScript Database, for Node.js, nw.js, electron and the browser
MIT License
13.46k stars 1.03k forks source link

How to make a field value is required(not empty)? #670

Open flight9 opened 3 years ago

flight9 commented 3 years ago

I think it's common that if we have a model called User, an email is required(not empty) when creating a new User Or we would stop the creating(like throw an error).

Is there a rule that can archieve this, like Index definition inside Nedb:

Model.ensureIndex({ fieldName: 'email', unique: true });

Model.ensureField({ fieldName: 'email', required: true }); //Is there a definition like this?