Skip to Content
몽고DB 완벽 가이드(3판): 실전 예제로 배우는 NoSQL 데이터베이스 기초부터 활용까지
book

몽고DB 완벽 가이드(3판): 실전 예제로 배우는 NoSQL 데이터베이스 기초부터 활용까지

by 김인범, 크리스티나 초도로우, 섀넌 브래드쇼, 오언 브라질
March 2021
Beginner to intermediate
600 pages
12h 19m
Korean
Hanbit Media, Inc.
Content preview from 몽고DB 완벽 가이드(3판): 실전 예제로 배우는 NoSQL 데이터베이스 기초부터 활용까지
113
4
쿼리
while (page1.hasNext()) {
latest = page1.next();
display(latest);
}
// 다음 페이지 가져오기
var page2 = db.foo.find({"date" : {"$lt" : latest.date}});
page2.sort({"date" : -1}).limit(100);
이제 쿼리에
skip
을 쓸 필요가 없다.
랜덤으로 도큐먼트 찾기
컬렉션에서 랜덤으로 도큐먼트를 가져오는 방법은 자주 문제가 된다. 단순하고 느린 방법으로
는 도큐먼트의 개수를 세고
find
를 실행한 후,
0
과 컬렉션 크기 사이의 수를 랜덤으로 뽑아 그
개수만큼 건너뛰는 방법이 있다.
> // 사용하지 말자.
> var total = db.foo.count()
> var random = Math.floor(Math.random()*total)
> db.foo.find().skip(random).limit(1)
이 방법은 사실 랜덤 요소를 구하는 데 매우 비효율적이다. 우선 전체 도큐먼트를 세어야 하며
(조건을 사용했다면 비용이 많이 들 수 있다), 많은 요소를 건너뛰어야 하므로 시간이 오래 걸
린다.
컬렉션에서 랜덤으로 요소를 찾아야 한다면 훨씬 효율적인 방법이 있다. 도큐먼트를 입력할 때
랜덤 키를 별도로 추가하는 방법이다. 예를 들어 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

풀스택 서버리스: 리액트, AWS, 그래프QL을 이용한 최신 애플리케이션 개발

풀스택 서버리스: 리액트, AWS, 그래프QL을 이용한 최신 애플리케이션 개발

김범준, 네이더 다빗

Publisher Resources

ISBN: 9791162244067