You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
+
1068
1098
#### Q. ***Mention the command to check whether you are on the master server or not?***
1069
1099
#### Q. ***Why MongoDB is not preferred over a 32-bit system?***
1070
1100
#### Q. ***What do you understand by NoSQL databases?***
0 commit comments