| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
- post
- Java
- 인생이재밌다
- Kubernetes
- spring
- chartjs
- AWS
- node.js
- jsp
- git
- AWS Route53
- zombie-hit apartment
- json
- 영화예매
- 예매로직
- ajax
- spread operator
- sessionStorage
- terminationGracePeriodSeconds
- MySQL Error
- ssh
- topologySpreadConstraints
- AWS RDS
- mysql
- javascript
- Get
- Bootstrap
- ES6
- mongodb
- html
- Today
- Total
jongviet
Aug 18, 2021 - MongoDB noSQL문 본문
*8월18일
-사용하면서 지속 업데이트 예정
*noSQLBooster for mongoDB
*단축키
command + enter -> 쿼리실행
*sql문
-비교문법
$eq // =
$gt // >
$gte // >=
$lt // <
$lte // <=
$ne // !=
$nin // matches none of the values specified in an array
$in // matches any of the values specified in an array
-insert
db.user.insertOne( {
name : "ki",
age : 31,
married : true //데이터 타입은 db가 알아서 지정함;
})
db.user.insertMany(
[
{name : "brown1", age: 31, married: false},
{name : "brown2", age: 32, married: false},
{name : "brown3", age: 33, married: false},
{name : "brown4", age: 34, married: false}
]
)
-find
db.user.find({})
.projection({})
.limit(100)
db.user.find({}) //전체검색
db.user.findOne(
{name : "brown1", age: {$gt : 30}} //greater than
)
db.user.find(
{ married : false, age : {$gt : 32}} // AND 조건
)
db.user.find(
{$or : [ {married: true}, {age : {$gt : 34}} ]} // OR 조건
)
db.user.find({
name : /ki/ // %ki%
});
db.user.find({
name : /^brown/ //brown%
});
db.user.find().count() == db.user.count()
db.user.find( {
test : { $exists: true} //해당 필드 존재 유무에 따라서 출력, true or false
}).count()
db.user.find( {
married : { $exists: true} //결혼 유무 존재 데이터 내림차
}).sort( {age : -1})
db.user.find(
{}, {age : 1, name : 1} // select age, name from user;
)
db.user.find(
{}, {age : 1, name : 1} // select age, name from user order by age desc limit 5;
).sort( {age : -1}).limit(5)
-update
db.user.updateMany(
{age : { $gte : 34} }, //filter 조건
{$set : { married : true } } //변경 내용
)
db.user.updateOne(
{name : "abrownd"},
{$set : {age : 50}}
)
db.user.updateOne({name : "jongki"}, { $inc : {age : 3}}) //$inc 사용해서 증감 가능
db.user.updateOne({name : "jongki"}, { $inc : {age : -3}})
-delete
db.user.deleteOne({ name : "brown1"})
db.user.deleteMany(
{age : {$lte : 32}}
)
-Data type
objectid : 생성일 + 랜덤벨류 + incrementing counter // 그냥 고유키, primary key 같음; 자동으로 생성됨;
int32 : 일반32bit int
-sort
.sort( { 정렬할 필드 : 1(오름차) or -1(내림차), ...... } ) //여러 조건 넣을 시 같은 중괄호안에
{ $sort: { <field1>: <sort order>, <field2>: <sort order> ... } }
.sort( { _id: 1 })
.limit(number)
.limit(5)
db.SessionHistory.find({}) //db.collection(table).find, select문
db.SessionHistory.find({})
.projection({})
.sort({_id:-1})
.limit(100)
'mongoDB' 카테고리의 다른 글
| Sep 22, 2021 - mongoDB 객체로 구성된 배열 쿼리 방법 (0) | 2021.09.22 |
|---|---|
| Sep 11, 2021 - mongoDB transaction (1) | 2021.09.11 |
| Sep 6, 2021 - mongoDB Atlas alert 및 인덱싱 점검 관련 (1) | 2021.09.06 |
| Aug 20, 2021 - mongoose populate (2) | 2021.08.20 |
| Aug 7, 2021 - postman 이용하여 mongoDB 데이터 넣기 (0) | 2021.08.07 |