오늘의 인기 글
최근 글
최근 댓글
Today
Total
05-03 06:06
관리 메뉴

우노

[MongoDB] Condition 본문

Database/MongoDB

[MongoDB] Condition

운호(Noah) 2020. 7. 3. 12:52

Condition

  • AND 조건

      db.collection.find({ status : "A", item : "paper" })
    
  • pretty ( 데이터를 보기 쉽게 )

      db.collection.find({ status : "A", item : "paper" }).pretty()
    

$ pedicate (속성)

  • $and, $or, $in, $lt, $gt.. 등

  • $and condition

      db.collection.find({ $and : [ {status : "A"}, {item : "paper"}]  })
    
  • $or condition

    • status가 A이거나 qty가 60 이하인 것

      • 어떤 상태에 들어갈 땐 항상 중괄호

          db.collection.find({$or : [{status:"A"},{qty : {$lt : 60}}]})
        
  • AND, OR condition

    • status가 A이며 qty가 40보다 작거나 80보다 큰거

        db.collection.find({
        status:"A",
        $or : [{qty : {$lt : 40}},{qty : {$gt : 80}}]
        })
      

기타 condition

  • 해당 필드가 존재하지 않는 도큐먼트를 출력!

      db.collection.find({ "dim_cm" : {$exists : false}})
    
  • 자바스크립트 쿼리

    • qty 필드의 value % 10 이 0인 도큐먼트 출력

        db.collection.find({ $where : "function() {return this.qty % 10 == 0;}" })
      

'Database > MongoDB' 카테고리의 다른 글

[MongoDB] CRUD  (0) 2020.07.03
[MongoDB] ArrayElement  (0) 2020.07.03
[MongoDB] Projection  (0) 2020.07.03
[MongoDB] Cursor  (0) 2020.07.03
[MongoDB] Aggregation  (0) 2020.07.03
Comments