1024programmer Java MongoDB add, delete, modify, query operation mongoose verification + set association

MongoDB add, delete, modify, query operation mongoose verification + set association

mongoose verification

When creating a collection rule, you can set the validation rules for the current field. If validation fails, insert failure will be entered

Commonly used validation rules provided within mongoose:

required: true required field or [ true , ‘ Please enter ×× ‘ ]

minlength: Minimum length of string maxlength Maximum length of string (error message can also be customized)

trim: remove spaces on both sides of the string

min: 2 The minimum value is 2

max: 100 The maximum value is 100

default: default value

enum: enumerates the values ​​that the current field can have

Custom validator:

validate: custom validator

MongoDB add, delete, modify and query operations mongoose verification + set association

set association

Usually there is a relationship between data in different collections. For example, article information and user information are stored in different collections, but the article is published by a user. To query all the information of the article including the publishing user, just Need to use collection association

  • Associate collections using ids
  • Use the populate method to query related collections

MongoDB add, delete, modify and query operations mongoose verification + set association

Collection association implementation

MongoDB add, delete, modify and query operations mongoose verification + set association

Case: Add, delete, modify and check user information

MongoDB add, delete, modify and query operations mongoose verification + set association

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/mongodb-add-delete-modify-query-operation-mongoose-verification-set-association/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: 34331943@QQ.com

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索