WIL

이건선·2023년 3월 5일
0

Node.js

목록 보기
19/32
  1. 간단 정규식
new RegExp(`^(?!.*${nickname}).*[A-Za-z0-9]{4,}$`);
// nickname 문자열을 포함하지 않으면서 [A-Za-z0-9]{4,} 배열안의 문자가 4개 이상
  1. map 메서드
const rename = users.map(({_id,name,ID,pw}) => {
    return {userId:_id, name:name,ID:ID,pw:pw}
  })
  1. find(), findOne()
    find() 메서드는 배열로서 값을 반환함에 유의하자

  2. mongodb virtual메서드 사용

postsSchema.virtual("postId").get(function () {
  return this._id.toHexString();
});

postsSchema.set("toJSON", {
  virtuals: true,
  transform: function (doc, ret) {
    delete ret._id;
    delete ret.id;
  },
profile
멋지게 기록하자

0개의 댓글