Skip to Content
MongoDB权威指南(第3版)
book

MongoDB权威指南(第3版)

by Shannon Bradshaw, Eoin Brazil, Kristina Chodorow
November 2021
Intermediate to advanced
410 pages
12h 1m
Chinese
Posts & Telecom Press
Content preview from MongoDB权威指南(第3版)
45
4
查询
本章会详细介绍查询,主要涵盖以下几个方面:
使用
$
条件进行范围查询、数据集包含查询、不等式查询,以及其他一些查询;
查询会返回一个数据库游标,其只会在需要时才惰性地进行批量返回;
有很多可以针对游标执行的元操作,包括跳过一定数量的结果、限定返回结果的数量,
以及对结果进行排序。
4.1
 
find
简介
我们在
MongoDB
中使用
find
方法来进行查询。查询就是返回集合中文档的一个子集,子
集的范围从
0
个文档到整个集合。要返回哪些文档由
find
的第一个参数决定,该参数是一
个用于指定查询条件的文档。
空的查询文档(
{}
)会匹配集合中的所有内容。如果
find
没有给定查询文档,则默认为
{}
例如:
> db.c.find()
将匹配集合
c
中的所有文档(并批量返回)。
当开始向查询文档中添加键
值对时
,就意味着限定了查询条件。这对于大多数类型来说
是一种简单明了的方式:数值匹配数值,布尔类型匹配布尔类型,字符串匹配字符串。查
询简单类型只要指定要查找的值就可以了。例如,要查找
"age"
值为
27
的所有文档,可以
将该键
值对添加到查询文档中:
> db.users.find({"age" : 27})
46
4
如果有一个要匹配的字符串,比如键
"username"
和它的值
"joe"
,则可以使用该键 ...
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

大数据项目管理:从规划到实现

大数据项目管理:从规划到实现

Ted Malaska, Jonathan Seidman
Go程序设计语言

Go程序设计语言

艾伦A. A.多诺万, 布莱恩W. 柯尼汉
Spark快速大数据分析(第2版)

Spark快速大数据分析(第2版)

Jules S. Damji, Brooke Wenig, Tathagata Das, Denny Lee
Kafka权威指南(第2版)

Kafka权威指南(第2版)

Gwen Shapira, Todd Palino, Rajini Sivaram, Krit Petty

Publisher Resources

ISBN: 9787115576538