Skip to content

Commit 7cd43db

Browse files
committed
Covered Query
1 parent 76563c5 commit 7cd43db

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,37 @@ ObjectId("5349b4ddd2781d08c09890f3")
10641064
<b><a href="#">↥ back to top</a></b>
10651065
</div>
10661066
1067-
#### Q. ***What is a covered query in MongoDB?***
1067+
## Q. ***What is a covered query in MongoDB?***
1068+
1069+
The MongoDB covered query is one which uses an index and does not have to examine any documents. An index will cover a query if it satisfies the following conditions:
1070+
1071+
* All fields in a query are part of an index.
1072+
* All fields returned in the results are of the same index.
1073+
* no fields in the query are equal to null
1074+
1075+
Since all the fields present in the query are part of an index, MongoDB matches the query conditions and returns the result using the same index without actually looking inside the documents.
1076+
1077+
**Example:**
1078+
1079+
A collection inventory has the following index on the type and item fields:
1080+
1081+
```js
1082+
db.inventory.createIndex( { type: 1, item: 1 } )
1083+
```
1084+
1085+
This index will cover the following operation which queries on the type and item fields and returns only the item field:
1086+
1087+
```js
1088+
db.inventory.find(
1089+
{ type: "food", item:/^c/ },
1090+
{ item: 1, _id: 0 }
1091+
)
1092+
```
1093+
1094+
<div align="right">
1095+
<b><a href="#">↥ back to top</a></b>
1096+
</div>
1097+
10681098
#### Q. ***Mention the command to check whether you are on the master server or not?***
10691099
#### Q. ***Why MongoDB is not preferred over a 32-bit system?***
10701100
#### Q. ***What do you understand by NoSQL databases?***

0 commit comments

Comments
 (0)