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 | 29 | 30 | 31 |
Tags
- GIT
- react
- 정렬
- game
- nestjs
- 자료구조
- MongoDB
- AWS
- Sequelize
- 게임
- JavaScript
- Python
- 공룡게임
- Nest.js
- typeORM
- OCR
- MySQL
- cookie
- TypeScript
- Express
- Dinosaur
- flask
- dfs
- mongoose
- class
- Queue
- jest
- Bull
- nodejs
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