3.33. MongoDB overlay index query

发布时间 : 2025-10-25 13:34:20 UTC      

Page Views: 10 views

The official MongoDB documentation states that the override query is the following query:

  • All query fields are part of the index

  • All query return fields are in the same index

Because all the fields that appear in the query are part of the index, MongoDB does not need to retrieve matching query criteria and return query results using the same index throughout the data document.

Because the index exists in RAM, it is much faster to get data from the index than to read it by scanning the document.

3.33.1. Use override index query

To test the override index query, use the following users collection:

{ "_id": ObjectId("53402597d852426020000002"), "contact": "987654321", "dob": "01-01-1991", "gender": "M", "name": "Tom Benzamin", "user_name": "tombenzamin" } 

We create a federated index in the users collection with the fields gender and user_name:

>db.users.createIndex({gender:1,user_name:1}) 

注: Versions prior to 5.0 can use the db.collection.ensureIndex() , but ensureIndex() Has been removed since version 5.0, using the createIndex() Instead.

The index now overrides the following query:

>db.users.find({gender:"M"},{user_name:1,_id:0}) 

In other words, for the above query, MongoDB will not look in the database file. Instead, it extracts data from the index, which is a very fast data query.

Since the_ id field is not included in our index,_ id is returned by default in the query, so we can exclude it from the query result set of MongoDB.

If_ id is not excluded from the following example, the query will not be overwritten:

>db.users.find({gender:"M"},{user_name:1}) 

Finally, you cannot use an override index query if it is the following query:

  • All index fields are an array

《地理信息系统原理、技术与方法》  97

最近几年来,地理信息系统无论是在理论上还是应用上都处在一个飞速发展的阶段。 GIS被应用于多个领域的建模和决策支持,如城市管理、区划、环境整治等等,地理信息成为信息时代重要的组成部分之一; “数字地球”概念的提出,更进一步推动了作为其技术支撑的GIS的发展。 与此同时,一些学者致力于相关的理论研究,如空间感知、空间数据误差、空间关系的形式化等等。 这恰好说明了地理信息系统作为应用技术和学科的两个方面,并且这两个方面构成了相互促进的发展过程。