ZeroTool Workbench
JSON → Mongoose 스키마
JSON에서 Mongoose 스키마를 즉시 생성. JavaScript·TypeScript 출력, timestamps, 중첩 객체·배열 지원. 무료, 브라우저에서 완전히 실행.
사용 방법
- 왼쪽 패널에 JSON을 붙여넣거나 입력합니다. 실시간으로 유효성이 검사됩니다.
- 모델 이름을 설정합니다(기본값:
User). 스키마 변수와 Mongoose 모델 이름으로 사용됩니다. - JavaScript 또는 TypeScript 출력 모드를 선택합니다.
- timestamps를 켜거나 끕니다.
- 스키마 생성을 클릭하거나 실시간 변환 결과를 기다립니다.
- 복사를 클릭하여 출력을 클립보드에 복사합니다.
타입 매핑
null→mongoose.Schema.Types.Mixed- 문자열 →
String - 숫자 →
Number - 불리언 →
Boolean - 기본 타입 배열 →
[String]/[Number]/[Boolean] - 객체 배열 →
[subSchema](별도 서브스키마 생성) - 중첩 객체 → 별도 스키마 변수를 인라인으로 참조
예시
모델 이름 User, 다음 JSON 입력 시:
{"username": "alice", "age": 28, "tags": ["admin"], "address": {"city": "London"}}
JavaScript 출력(timestamps 켜짐):
const mongoose = require('mongoose');
const { Schema } = mongoose;
const addressSchema = new Schema({
city: { type: String },
});
const userSchema = new Schema({
username: { type: String },
age: { type: Number },
tags: [String],
address: addressSchema,
}, { timestamps: true });
module.exports = mongoose.model('User', userSchema); FAQ
이 도구는 무엇을 생성하나요?
JSON에서 Mongoose 스키마 정의를 생성합니다. 중첩 객체는 별도의 스키마 변수가 되며, 하단에 model export 구문이 포함됩니다.
어떤 언어 모드를 지원하나요?
JavaScript(CommonJS require/module.exports)와 TypeScript(ES module import/export, Document 인터페이스와 제네릭 스키마 포함)를 지원합니다.
JSON 타입은 Mongoose 타입으로 어떻게 매핑되나요?
string→String, number→Number, boolean→Boolean, null→mongoose.Schema.Types.Mixed, 기본 타입 배열→[Type], 객체 배열→별도 서브스키마, 중첩 객체→별도 서브스키마.
timestamps 옵션은 어떤 역할을 하나요?
켜면 { timestamps: true }로 스키마가 생성되어 Mongoose가 createdAt, updatedAt 필드를 자동으로 관리합니다.
모든 필드가 required로 생성되나요?
아닙니다. JSON만으로는 필드의 required 여부를 알 수 없으므로 기본적으로 required: true 없이 생성됩니다. 필요에 따라 직접 추가하세요.
데이터가 서버로 전송되나요?
아닙니다. 전체 변환이 브라우저에서 실행됩니다. 데이터는 외부로 전송되지 않습니다.