-
Notifications
You must be signed in to change notification settings - Fork 34
DOCSP-41983: indexes landing pg #127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rustagir
merged 9 commits into
mongodb:php-standardization
from
rustagir:DOCSP-41983-indexes-landing
Sep 10, 2024
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3cae058
DOCSP-41983: indexes landing pg
rustagir d65dae9
wip
rustagir 2477f39
wip
rustagir 4abb6de
MM PR fixes 1
rustagir e227a7f
JM tech review 1
rustagir b18b221
JM tech review 1
rustagir a8de178
wip
rustagir 69668bd
wip
rustagir cbc3879
JM tech review 2
rustagir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?php | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$uri = getenv('MONGODB_URI') ?: throw new RuntimeException('Set the MONGODB_URI variable to your Atlas URI that connects to the sample dataset'); | ||
$client = new MongoDB\Client($uri); | ||
|
||
$database = $client->sample_db; | ||
$collection = $database->sample_coll; | ||
|
||
// start-to-json | ||
function toJSON(object $document): string | ||
{ | ||
return MongoDB\BSON\Document::fromPHP($document)->toRelaxedExtendedJSON(); | ||
} | ||
// end-to-json | ||
|
||
// start-single-field | ||
$indexName = $collection->createIndex(['<field name>' => 1]); | ||
// end-single-field | ||
|
||
// start-compound | ||
$indexName = $collection->createIndex( | ||
['<field name 1>' => 1, '<field name 2>' => 1] | ||
); | ||
// end-compound | ||
|
||
// start-multikey | ||
$indexName = $collection->createIndex(['<array field name>' => 1]); | ||
// end-multikey | ||
|
||
// start-search-create | ||
$indexName = $collection->createSearchIndex( | ||
['mappings' => ['dynamic' => true]], | ||
['name' => '<Search index name>'] | ||
); | ||
// end-search-create | ||
|
||
// start-search-list | ||
foreach ($collection->listSearchIndexes() as $indexInfo) { | ||
echo toJSON($indexInfo) . PHP_EOL; | ||
jmikola marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
// end-search-list | ||
|
||
// start-search-update | ||
$collection->updateSearchIndex( | ||
'<Search index name>', | ||
['mappings' => [ | ||
'dynamic' => false, | ||
'fields' => [ | ||
'<string field name>' => [ | ||
'type' => 'string', | ||
'analyzer' => 'lucene.standard' | ||
] | ||
] | ||
]] | ||
); | ||
// end-search-update | ||
|
||
// start-search-delete | ||
$collection->dropSearchIndex('<Search index name>'); | ||
// end-search-delete | ||
|
||
// start-text | ||
$indexName = $collection->createIndex(['<field name>' => 'text']); | ||
// end-text | ||
|
||
// start-geo | ||
$indexName = $collection->createIndex( | ||
[ '<GeoJSON object field>' => '2dsphere'] | ||
); | ||
// end-geo | ||
|
||
// start-unique | ||
$indexName = $collection->createIndex(['<field name>' => 1], ['unique' => true]); | ||
// end-unique | ||
|
||
// start-wildcard | ||
$indexName = $collection->createIndex(['$**' => 1]); | ||
// end-wildcard | ||
|
||
// start-clustered | ||
$options = [ | ||
'clusteredIndex' => [ | ||
'key' => ['_id' => 1], | ||
'unique' => true | ||
] | ||
]; | ||
|
||
$database->createCollection('<collection name>', $options); | ||
rustagir marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// end-clustered | ||
|
||
// start-list | ||
foreach ($collection->listIndexes() as $indexInfo) { | ||
echo $indexInfo; | ||
} | ||
// end-list | ||
|
||
// start-remove | ||
$collection->dropIndex('<index name>'); | ||
// end-remove |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Sample Application | ||
~~~~~~~~~~~~~~~~~~ | ||
|
||
You can use the following sample application to test the code examples on this | ||
page. To use the sample application, perform the following steps: | ||
|
||
1. Ensure you have the {+php-library+} installed in your project. | ||
#. Copy the following code and paste it into a new ``.php`` file. | ||
#. Copy a code example from this page and paste it on the specified | ||
lines in the file. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$uri = getenv('MONGODB_URI') ?: throw new RuntimeException('Set the MONGODB_URI variable to your Atlas URI that connects to the sample dataset'); | ||
$client = new MongoDB\Client($uri); | ||
|
||
$collection = $client->selectCollection('<database>', '<collection>'); | ||
|
||
// Start example code here | ||
|
||
// End example code here |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ MongoDB PHP Library | |
/read | ||
/write | ||
/aggregation | ||
/indexes | ||
/tutorial | ||
/upgrade | ||
/reference | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.