NoSQL
고정된 테이블이 없고, 테이블에 상응하는 컬렉션이 존재
데이터의 일관성을 보장해주는 기능은 약하지만, 데이터를 빠르게 넣을 수 있고, 쉽게 여러 서버에 데이터를 분산할 수 있다.
MongoDB와 SQL 을 함께 사용하기도
schemas / comments.js
const mongoose = require('mongoose');
const {Schema} = mongoose;
const commentSchema = new Schema({
commenter : {
type : ObjectId,
required : true,
ref : 'User',
},
comment : {
type : String,
required : true,
},
});
module.exports = mongoose.model('Comment',commentSchema);
model 메서드의 첫번째 인수를 소문자로 바꾼 후 복수형으로 바꿔서 컬렉션 이름을 만든다.
commenter 속성에서, type 이 ObjectId 이다. ref 속성의 값이 User → commenter 필드에 User 스키마의 사용자 id 가 들어간다는 뜻
컬렉션 이름을 따로 설정하고 싶다면 세번째 인수로 설정 가능하다.
mongoose.model('Comment',commentSchema, tb_comment);