Skip to content

Commit e6942b4

Browse files
committed
post: mongodb exec(), lean()
1 parent 0d5bd01 commit e6942b4

10 files changed

+74
-129
lines changed

Gemfile

+3
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ gem "kramdown-parser-gfm"
66

77
gemspec
88
gem "webrick", "~> 1.8"
9+
10+
11+
gem 'jekyll-admin', group: :jekyll_plugins

Gemfile.lock

+24
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ GEM
3535
pathutil (~> 0.9)
3636
rouge (>= 1.7, < 4)
3737
safe_yaml (~> 1.0)
38+
jekyll-admin (0.11.1)
39+
jekyll (>= 3.7, < 5.0)
40+
sinatra (>= 1.4)
41+
sinatra-contrib (>= 1.4)
3842
jekyll-feed (0.15.1)
3943
jekyll (>= 3.7, < 5.0)
4044
jekyll-sass-converter (1.5.2)
@@ -52,26 +56,46 @@ GEM
5256
rb-fsevent (~> 0.10, >= 0.10.3)
5357
rb-inotify (~> 0.9, >= 0.9.10)
5458
mercenary (0.3.6)
59+
multi_json (1.15.0)
60+
mustermann (3.0.0)
61+
ruby2_keywords (~> 0.0.1)
5562
pathutil (0.16.2)
5663
forwardable-extended (~> 2.6)
5764
public_suffix (5.0.3)
65+
rack (2.2.7)
66+
rack-protection (3.0.6)
67+
rack
5868
rb-fsevent (0.11.2)
5969
rb-inotify (0.10.1)
6070
ffi (~> 1.0)
6171
rexml (3.2.5)
6272
rouge (3.30.0)
73+
ruby2_keywords (0.0.5)
6374
safe_yaml (1.0.5)
6475
sass (3.7.4)
6576
sass-listen (~> 4.0.0)
6677
sass-listen (4.0.0)
6778
rb-fsevent (~> 0.9, >= 0.9.4)
6879
rb-inotify (~> 0.9, >= 0.9.7)
80+
sinatra (3.0.6)
81+
mustermann (~> 3.0)
82+
rack (~> 2.2, >= 2.2.4)
83+
rack-protection (= 3.0.6)
84+
tilt (~> 2.0)
85+
sinatra-contrib (3.0.6)
86+
multi_json
87+
mustermann (~> 3.0)
88+
rack-protection (= 3.0.6)
89+
sinatra (= 3.0.6)
90+
tilt (~> 2.0)
91+
tilt (2.2.0)
6992
webrick (1.8.1)
7093

7194
PLATFORMS
7295
arm64-darwin-22
7396

7497
DEPENDENCIES
98+
jekyll-admin
7599
kramdown-parser-gfm
76100
no-style-please!
77101
webrick (~> 1.8)

_config.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
title: no style, please! # name of the site
2-
author: Riccardo Graziosi # name of site's author
3-
email: riccardo.graziosi97@gmail.com # email of site's author
1+
title: HyunPang's blog! # name of the site
2+
author: HyunPang # name of site's author
3+
email: mabr2845@gmail.com # email of site's author
44
url: https://hyun-git.github.io/ # root address of the site
55
baseurl: "" # subpath of the site, e.g. "/blog" (leave it blank "" if you're site shouldn't use a subpath)
66
description: > # description of the site (multiple lines allowed)
7-
A (nearly) no-CSS, fast, minimalist Jekyll theme.
7+
HyunPang's IT Blog
88
99
permalink: /:slug.html
1010

_data/menu.yml

+7-6
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44
entries:
55
- title: info
66
entries:
7-
- title: a (nearly) no-CSS, fast, minimalist Jekyll theme.
8-
- title: github repo
9-
url: https://github.com/riggraz/no-style-please
10-
- title: "used by <a href='https://riggraz.dev'>riggraz.dev</a> and <a href='https://github.com/riggraz/no-style-please/network/dependents'>many others</a>"
7+
- title: "Author: HyunPang"
8+
- title: GitHub
9+
url: https://github.com/Hyun-git
10+
- title: "[email protected]"
11+
1112

12-
- title: all posts
13+
- title: For Study
1314
post_list:
1415
limit: 5
1516
show_more: true
16-
show_more_text: See archive...
17+
show_more_text: More Posts
1718
show_more_url: archive.html
1819

1920
- title: posts by category

_posts/2020-07-06-strange-post.md

-6
This file was deleted.

_posts/2020-07-08-language-tests.md

-52
This file was deleted.

_posts/2020-07-08-very-very-very-long-title-and-very-very-very-short-content.md

-6
This file was deleted.

_posts/2020-07-09-post-example-with-headings-and-toc.md

-27
This file was deleted.

_posts/2020-07-09-post-example-with-hr.md

-28
This file was deleted.

_posts/2023-07-20-LeanAndExec.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
title: Mongodb lean() And exec()
3+
layout: post
4+
---
5+
6+
## 목차
7+
- [Lean](#lean)
8+
- [Exec](#exec)
9+
10+
11+
`mongoose` 쿼리를 보게 되면 `<query>.lean().exec()` 과 같이 쿼리 뒤에 `lean(), exec()` 메소드가 붙어 있는 경우를 볼 수 있다. 해당 메소드들에 대해 궁굼한 점이 생겨 공부를 하게 되었다.
12+
# Lean
13+
- [공식문서](https://mongoosejs.com/docs/tutorials/lean.html)
14+
- [참고한 블로그](https://choonse.com/2022/02/23/1000/)
15+
16+
`mongoose`의 리턴값은 `Document` 클래스의 인스턴스라고 한다.
17+
18+
해당 인스턴스는 많은 `state`를 가지고 있어 다양한 작업을 가능하게 한다.
19+
20+
예를 들어 `.get(), .set(), .toObject() ...`과 같이 리턴값에 대한 메소드 사용이 가능하고 해당 메소드에 대한 결과로 다시 쿼리를 진행하는 방식도 가능하다.
21+
22+
하지만 단지 결과 데이터를 목적으로 하는 `find()` 쿼리과 같은 작업에서는 결과값에 대해 추가로 작업을 하지는 않는다 . 이때 `lean()`을 사용하게 된다.
23+
24+
쿼리에 `lean()`을 추가하게 되면 인스턴스가 아닌 `POJO(Plain Old Javascript Object)`를 리턴하게 한다.
25+
26+
> [POJO](https://ko.wikipedia.org/wiki/Plain_Old_Java_Object) 객체 지향적인 원리에 충실하면서 환경과 기술에 종속되지 않고, 필요에 따라 재활용될 수 있는 방식으로 설계된 오브젝트를 의미한다. 이러한 POJO에 애플리케이션의 핵심 로직과 기능을 담아 설계하고 개발하는 방법을 POJO 프로그래밍이라고 한다.
27+
28+
즉 메서드와 같은 데이터를 함께 반환하지 않으니 속도와 메모리면에서 큰 장점을 가지고 쿼리를 날릴 수 있게 되는 것이다.
29+
30+
# Exec
31+
- [공식문서](https://mongoosejs.com/docs/tutorials/lean.html)
32+
- [참고한 블로그](https://tesseractjh.tistory.com/166)
33+
34+
`find(), findOne() ...` 등의 리턴값은 `query`이다. 몽구스의 쿼리는 프로미스가 아닌 `then()`을 사용하는 유사 프로미스라고한다.
35+
36+
실제 뒤에 `exec()`를 붙이든 안붙이든 기능은 동일하다. 하지만 붙이게 되면 유사 프로미스가 아닌 완전한 프로미스를 얻을 수 있고 에러가 났을 때 `stacktrace`에 오류가 발생한 코드의 위치가 포함 되기에 공식 문서에서도 `exec()`를 사용할 것을 권장하고 있다.

0 commit comments

Comments
 (0)