
Schema::getCollectionAsTable 메소드는 Mongoose 6.7.2 버전부터 지원됩니다. 이 메소드는 mongoose.model()로 생성된 모델의 컬렉션을 테이블 형태로 조회할 수 있도록 도와줍니다.
다음은 예시입니다.
#hostingforum.kr
javascript
const mongoose = require('mongoose');
const userSchema = new mongoose.Schema({
name: String,
age: Number,
email: String
});
const User = mongoose.model('User', userSchema);
const users = await User.find();
const table = await User.getCollectionAsTable(users);
console.log(table);
이 코드는 User 모델의 컬렉션을 테이블 형태로 조회합니다. 결과는 다음과 같습니다.
#hostingforum.kr
markdown
| name | age | email |
|------|-----|-------|
| John | 25 | john@example.com |
| Jane | 30 | jane@example.com |
getCollectionAsTable 메소드는 mongoose.model()로 생성된 모델의 컬렉션을 테이블 형태로 조회할 수 있도록 도와줍니다. 이 메소드는 mongoose 6.7.2 버전부터 지원됩니다.
2025-04-19 10:39