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
- getModifierState
- react env
- github
- rewrites
- npm styled-reset
- SCSS
- ngrok실행
- There isn’t anything to compare
- bootstrap
- createGlobalStyle
- styled components
- dart 변수
- input type=file
- react
- nextjs 설치
- API token
- icon
- nextjs
- Git
- nextjs .env
- typescript react
- 컨디셔널 렌더링
- ngrok설치
- git lab
- CSS
- react typescript
- fetch
- next.js css
- API 토큰
- github io
Archives
- Today
- Total
꾸준히 성장하는 개발자
[MongoDB ] mongoose /model? Schema?? 본문
MongoDB
- NoSQL 데이터베이스 시스템이다. 데이터베이스 그 자체
Mongoose
- Node.js와 MongoDB를 연결해주는 드라이버
- mongoDB의 객체 모델링 도구
MongoDB는 noSql이기 때문에 정해진 스키마가 없어 한 데이터 셋에서
여러 종류의 데이터셋이 섞여있는 경우가 생길 수 있다.
mongoose는 이런일들을 방지하기 위해 스키마를 정의하는 기능을 제공하고 이를 필수로 규정해놓았다.
mongoose로 mongoDB연결하기
const mongoose = require("mongoose");
mongoose
.connect("mongodb주소")
.then(() => console.log("MongoDB Connected..."))
.catch((err) => console.log(err));
스키마 만들기
//mongoose 불러오기
const mongoose = require("mongoose");
//스키마 생성하기
const userSchema = mongoose.Schema({
name: {type: String, maxlength: 50},
email: {type: String, trim: true, unique: 1, minlength: 5 },
password: {type: String, minlength: 5},
lastname: {type: String, maxlength: 50 }
});
//스키마를 모델로 감싸주기, 스키마를 등록해줌
const User = mongoose.model("User", userSchema);
// ( 모델의 이름, 스키마)
'Node.js' 카테고리의 다른 글
[Error] Mac / IDE에서 zsh: command not found: nvm (0) | 2023.08.17 |
---|