본문 바로가기
로그

몽고DB 쿼리 조회 (MongoDB Query)

by kimnampill 2023. 4. 25.
728x90
반응형

[전화번호 검색]
db.getCollection("KoreaDB").find({"phoneNumber": {"$in": ["821011112222", "821022223333".... "821033334444"]}})


[NumberLong 타입으로 userID 찾기]
db.getCollection("KoreaDB").find({ "userId": { "$eq": NumberLong(1234567) } })

[연번 추가]
var seq = 0
db.KoreaDB.find().sort({_id: 1}).forEach(function(doc) {
    db.KoreaDB.updateOne({_id: doc._id}, {$set: {seq: ++seq}})
})

[userID 대량 조회]
db.KoreaDB.find({userId: {$in: [1,2,3,4,5,6....999999]}}).sort({userId: 1})

[IP 중복제거]
db.AccessLOG.aggregate([
  {
    $group: {
      _id: "$ip",
      path: { $first: "$path" },
      createdAt: { $first: "$createdAt" },
      body: { $first: "$body" }
    }
  }
])

반응형

댓글