티스토리 뷰
728x90
반응형
테이블(컬렉션)에 있는 모든 데이터 조회하기
// MongoDB
db.table.find({})
// MySQL
SELECT * FROM table
테이블(컬렉션)에 있는 _id를 제외한 데이터 조회하기
// MongoDB
db.table.find({}, {_id:0})
// MySQL
SELECT name, password FROM table
테이블(컬렉션)에 있는 _id와 name을 포함해서 데이터 조회하기
// MongoDB
db.table.find({}, {name:1})
// MySQL
SELECT id, name FROM table
테이블(컬렉션)에 있는 _id를 제외하고 name만 포함해서 데이터 조회하기
// MongoDB
db.table.find({}, {name:1, _id:0})
// MySQL
SELECT name FROM table
테이블(컬렉션)에 있는 name이 domdomi 인 데이터만 조회하기
// MongoDB
db.table.find({name: "domdomi"})
// MySQL
SELECT * FROM table WHERE name="domdomi"
테이블(컬렉션)에 있는 age가 10보다 큰 데이터만 조회하기
// MongoDB
db.table.find({"age": { $gt: 10 }})
// MySQL
SELECT * FROM table WHERE age > 10
테이블(컬렉션)에 있는 age가 10보다 크거나 같은 데이터만 조회하기
// MongoDB
db.table.find({"age": { $gte: 10 }})
// MySQL
SELECT * FROM table WHERE age >= 10
테이블(컬렉션)에 있는 age가 20보다 작거나 같은 데이터만 조회하기
// MongoDB
db.table.find({"age": { $lte: 20 }})
// MySQL
SELECT * FROM table WHERE age <= 20
테이블(컬렉션)에 있는 age가 20보다 작은 데이터만 조회하기
// MongoDB
db.table.find({"age": { $lt: 20 }})
// MySQL
SELECT * FROM table WHERE age < 20
위 예시들은 SQL 에서 특정 데이터를 추출하는 부분으로써 projection 에 해당하는 부분입니다. 더 많은 사용법은 MongoDB 문서를 참고하면 좋을 것 같습니다.
참고 : https://docs.mongodb.com/manual/tutorial/project-fields-from-query-results/
Project Fields to Return from Query — MongoDB Manual
Docs Home → MongoDB Manual➤ Use the Select your language drop-down menu in the upper-right to set the language of the following examples.By default, queries in MongoDB return all fields in matching documents. To limit the amount of data that MongoDB se
docs.mongodb.com
728x90
반응형
'프로그래밍 > Node.js' 카테고리의 다른 글
[Nodejs] http-proxy 프록시로 웹 출력하기 (0) | 2023.09.27 |
---|---|
[Nodejs] 프로젝트 생성하기 (0) | 2023.09.26 |
[Mongodb] 하나의 Field를 다른 Field 로 수정하는 방법 (0) | 2021.07.12 |
[Nodejs - Mongoose] Schema에서 default 값을 현재 시간으로 하는 법 (4) | 2021.07.07 |
[오류해결] Node Sass version 6.0.0 is incompatible with ^4.0.0 || ^5.0.0. (0) | 2021.05.13 |
댓글