Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- Dinosaur
- MySQL
- TypeScript
- Sequelize
- Nest.js
- 게임
- 정렬
- nestjs
- MongoDB
- class
- flask
- Python
- Queue
- typeORM
- GIT
- jest
- AWS
- dfs
- nodejs
- Express
- 공룡게임
- OCR
- game
- cookie
- 자료구조
- Bull
- JavaScript
- mongoose
- react
Archives
- Today
- Total
목록Virtual (1)
포시코딩
[Mongoose] Schema.virtual을 통해 _id(ObjectId)를 다른 이름으로 변경하기
const mongoose = require('mongoose'); const postSchema = new mongoose.Schema({ // ...생략 }); postSchema.virtual('postId').get(function() { return this._id.toHexString(); // 이 부분의 this._id에 해당하는 부분을 가상화 시킨다. }); postSchema.set('toJSON', { virtuals: true }); module.exports = mongoose.model("Post", postSchema); mongoose에서 제공하는 Schema의 가상화를 이용하는 방법인데 위에 코드에 적혀있듯, 이 Schema가 JSON화 될 때 this._id 즉, 이 스키마..
MongoDB
2022. 12. 14. 12:12