MongoDB Query APIMongoDB查询API
On this page本页内容
The MongoDB Query API is the mechanism that you use to interact with your data.MongoDB Query API是用于与数据交互的机制。
The Query API comprises two ways to query data in MongoDB:查询API包括两种在MongoDB中查询数据的方法:
You can use the Query API to perform:您可以使用查询API来执行:
Adhoc queries临时查询. Explore your MongoDB data with。使用mongosh
, Compass , VSCodeor a MongoDB driver.
mongosh
、Compass、VSCode或MongoDB驱动程序探索您的MongoDB数据。
Data transformations数据转换. Use aggregation pipelines to reshape your data and perform calculations.。使用聚合管道重塑数据并执行计算。Document join support文档加入支持Use使用$lookup
and$unionWith
to combine data from different collections.$lookup
和$unionWith
组合来自不同集合的数据。Graph and geospatial queries图形和地理空间查询. Use operators such as。使用$geoWithin
and$geoNear
to analyze geospatial data and$graphLookup
for graph data.$geoWithin
和$geoNear
等运算符来分析地理空间数据,并使用$graphLookup
来分析图形数据。Full-text search全文搜索. Use the。使用$search
stage to perform efficient text search on your data.$search
阶段可以对数据执行高效的文本搜索。Indexing索引. Improve your MongoDB query performance by using the correct index type for your data architecture.。通过为您的数据体系结构使用正确的索引类型来提高MongoDB查询性能。On-demand materialized views按需物化视图. Use。使用$out
and$merge
to create materialized views on common queries.$out
和$merge
可以在常见查询上创建物化视图。Time series analysis时间序列分析. Query and aggregate your time-stamped data with time series collections.。使用时间序列集合查询和聚合带有时间戳的数据。
Document Model文档模型
A document in MongoDB is a data structure composed of field and value pairs. MongoDB中的文档是由字段和值对组成的数据结构。Documents are stored as BSON which is the binary representation of JSON. 文档存储为BSON,它是JSON的二进制表示。This low level of abstraction helps you develop quicker and reduces the efforts around querying and data modeling. 这种低级别的抽象可以帮助您更快地进行开发,并减少查询和数据建模方面的工作量。The document model provides several advantages, including:文档模型提供了几个优点,包括:
Documents correspond to native data types in many programming languages.文档对应于许多编程语言中的本机数据类型。Embedded documents and arrays reduce need for expensive joins.嵌入式文档和数组减少了对昂贵联接的需求。Flexible schema. Documents do not need to have the same set of fields and the data type for a field can differ across documents within a collection.灵活的架构。文档不需要具有相同的字段集,并且集合中不同文档的字段的数据类型可能不同。
Data as Code数据作为代码
The MongoDB Query API supports drivers for major programming languages. MongoDB Query API支持主要编程语言的驱动程序。These drivers allow you to make calls to the database and generate queries using the syntax native to your application.这些驱动程序允许您调用数据库,并使用应用程序的本地语法生成查询。
Getting Started入门
To get started, visit the MongoDB Getting Started Guide. Here you can find resources, code examples and tutorials that demonstrate the MongoDB Query API.要开始,请访问MongoDB入门指南。在这里,您可以找到演示MongoDB Query API的资源、代码示例和教程。