[MongoDB] query 명령어 정리

HI·2024년 8월 7일

insert

db.test.insertOne(
     { subject: "coffee", author: "xyz", views: 50 }
)

https://www.fun-coding.org/post/mongodb_basic4.html#gsc.tab=0

DB 생성/삭제, collection 생성/데이터 insert

https://velopert.com/457

SELECT

조회

db.getCollection("name").find()

n개의 결과 조회 limit()

db.getCollection("name").find().limit(n) 

https://hoing.io/archives/1612

_id 검색 (Object)

db.getCollection("name").find({"_id":123})

id가 n이상의 결과

db.getCollection("name").find({'_id': {'$gt': last_id}}})

정렬

_id값으로 오름차순 정렬

db.getCollection("name").find({}).sort({"_id":1})

1이면 오름차순, -1 이면 내림차순 정렬

python 몽고DB 연동

https://wooiljeong.github.io/python/mongodb-01/
https://sarc.io/index.php/nosql/835-pymongo-python-mongodb
https://homzzang.com/b/py-54

collection 삭제

db.getCollection("fs.chunks").deleteOne({"_id":123})

0개의 댓글