How to check if that data already exist in the database during update (Mongoose And Express)

后端 未结 8 1881
灰色年华
灰色年华 2020-12-05 00:28

How to do validations before saving the edited data in mongoose?

For example, if sample.name already exists in the database, the user will receive a som

8条回答
  •  独厮守ぢ
    2020-12-05 00:36

    If you're searching by an unique index, then using UserModel.count may actually be better for you than UserModel.findOne due to it returning the whole document (ie doing a read) instead of returning just an int.

提交回复
热议问题