express-session을 사용할 때마다 설정해주는 두 가지 옵션이 있다. resave와 saveUnitailzed. saveUnitiailzed: Forces a session that is "uninitialized" to be saved to the store. A session is uninitialized when it is new but not modified. session이 처음 만들어졌을 때 session을 수정하지 않는다면 session은 unintialzied 상태이다. 그 session을 저장할 것 이냐 true(저장할 것이다.) or false(저장하지 않을 것이다.) app.use(session({ resave: true, saveUninitialized: false, sec..
alias는 특별한 virtual 타입이다. alias는 network 대역폭을 절약하는데 도움이 된다. 실제 DB에는 짧은 프로퍼티 이름을 저장하고 실제 코드에서는 긴 프로퍼티 이름을 사용할 수 있다. const personSchema = new Schema({ n: { type: String, // Now accessing 'name' will get you the value of 'n', // and setting 'n' will set the value of 'name' alias: 'name' } }) const Person = mongoose.model('Person', personSchema); // Setting 'name' will propagate to 'n' const person =..
virtuals는 MongoDB에 실재하지 않는 access property(getter나 setter)다. getter는 formatting이나 combining 하는데 유용하고 setter는 하나의 값을 여러개의 값으로 분해하는데 유용하다. Axl Rose라는 사람이 있다고 하면 // define a schema var personSchema = new Schema({ name: { first: String, last: String } }); // compile our model var Person = mongoose.model('Person', personSchema); // create a document var axl = new Person({ name: { first: 'Axl', last: ..
Mongoose에서 인덱스를 선언하는 방법은 2가지가 있다. path level(또는 field level)에서 정의하는 법과 schema level에서 정의하는 법. 스키마를 정의하면서 field level에서 정의할 수 있고, schema정의가 끝나고 index() 메서드를 통해서 정의할 수도 있다. compound index를 만드려면 index() 메서드를 사용해야 한다. const animalSchema = new Schema({ name: String, type: String, tags: { type: [String], index: true } // field level }); animalSchema.index({ name: 1, type: -1 }); // schema level const ..
Query Helper는 instance method와 유사하지만 mongoose queries에만 쓰이는 helper function이다. Query Helper는 말 그대로 mongoose의 chainable 한 mongoose의 query builder API를 확장시켜주는 method다. 스키마를 정의. const animalSchema = new Schema({ name: String, breed: String }); query property에 query helper를 정의후 컴파일. animalSchema.query.byName = function (name) { return this.where({ name: new RegExp(name, 'i') }); } const Animal = mon..
- Total
- Today
- Yesterday
- index
- mongoose
- 맵
- alias
- mixin
- MongoDB
- virtuals
- static method
- 이중 연결리스트
- instance method
- saveUnitialized
- pm2 #cluster #Javascript
- 다형성
- 자료구조
- Iterator
- 선형리스트
- 집합
- resave
- query helper
- map
- javascript
- Generator
- 자료구조 #딕셔너리 #해시
- set
- 다중상속
- Node.js
- express-session
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |