note 117836 added to mongocursor.hint
| From: | mr dot bipinks at gmail dot com | Date: | Tue, 18 Aug 2015 04:18:18 +0000 |
| Subject: | note 117836 added to mongocursor.hint | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-203370@lists.php.net to get a copy of this message | ||
For the series weâll assume we have a collection named posts populated with 500 documents
having the following structure:
{
"_id": ObjectId("5146bb52d852470060001f4"),
"comments": {
"0": "This is the first comment",
"1": "This is the second comment"
},
"post_likes": 40,
"post_tags": {
"0": "MongoDB",
"1": "Tutorial",
"2": "Indexing"
},
"post_text": "Hello Readers!! This is my post text",
"post_type": "private",
"user_name": "Mark Anthony"
}
The hint() method can be used to force MongoDB to use an index we specify and override the default
selection and query optimization process. You can specify the field names used in the index as a
argument as shown below:
<?php
// query to find posts with type public and 100 likes
// use hint() to force MongoDB to use the index we created
$cursor = $collection
->find(
array(
"post_type" => "public",
"post_likes" => 100
)
)
->hint(
array(
"post_type" => 1,
"post_likes" => 1
)
);
?>
This ensures the query uses the compound index defined on the post_type and post_likes fields.
----
Server IP: 72.52.91.14
Probable Submitter: 202.88.246.140
----
Manual Page -- http://php.net/manual/en/mongocursor.hint.php
Edit -- https://master.php.net/note/edit/117836
Del: integrated -- https://master.php.net/note/delete/117836/integrated
Del: useless -- https://master.php.net/note/delete/117836/useless
Del: bad code -- https://master.php.net/note/delete/117836/bad+code
Del: spam -- https://master.php.net/note/delete/117836/spam
Del: non-english -- https://master.php.net/note/delete/117836/non-english
Del: in docs -- https://master.php.net/note/delete/117836/in+docs
Del: other reasons-- https://master.php.net/note/delete/117836
Reject -- https://master.php.net/note/reject/117836
Search -- https://master.php.net/manage/user-notes.php