-
Notifications
You must be signed in to change notification settings - Fork 51
DOCSP-30756: add list search indexes to cursor page #704
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
nickldp
merged 10 commits into
mongodb:master
from
nickldp:DOCSP-30756-add-listSearchIndexes-to-Cursor-pg
Jun 28, 2023
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c2a5560
first draft
nickldp 6f16227
first draft
nickldp cd551bd
first draft
nickldp 93e332e
first draft
nickldp b3bcf76
first draft
nickldp 9363c6c
first draft v1.1
nickldp 314d3c0
big fixes
nickldp c4e33d5
big fixes
nickldp 0173472
review fixes
nickldp 7c177b8
final
nickldp 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,27 @@ | ||
const { MongoClient } = require("mongodb"); | ||
|
||
// Replace the following with your MongoDB deployment's connection | ||
// string. | ||
const uri = | ||
"mongodb+srv://<user>:<password>@<cluster-url>?writeConcern=majority"; | ||
|
||
const client = new MongoClient(uri); | ||
|
||
import { MongoClient } from "mongodb"; | ||
const database = client.db("<databaseName>"); | ||
const collection = database.collection("<collectionName>"); | ||
|
||
async function run() { | ||
try { | ||
// start listIndexes example | ||
const result = await collection.listIndexes().toArray(); | ||
console.log("Existing indexes:\n"); | ||
for(const doc in result){ | ||
console.log(doc); | ||
} | ||
// end listIndexes example | ||
} finally { | ||
await client.close(); | ||
} | ||
} | ||
run().catch(console.dir); |
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,27 @@ | ||
const { MongoClient } = require("mongodb"); | ||
|
||
// Replace the following with your MongoDB deployment's connection | ||
// string. | ||
const uri = | ||
"mongodb+srv://<user>:<password>@<cluster-url>?writeConcern=majority"; | ||
|
||
const client = new MongoClient(uri); | ||
|
||
import { MongoClient } from "mongodb"; | ||
const database = client.db("<databaseName>"); | ||
const collection = database.collection("<collectionName>"); | ||
|
||
async function run() { | ||
try { | ||
// start listSearchIndexes example | ||
const result = await collection.listSearchIndexes().toArray(); | ||
console.log("Existing search indexes:\n"); | ||
for(const doc in result){ | ||
console.log(doc); | ||
} | ||
// end listSearchIndexes example | ||
} finally { | ||
await client.close(); | ||
} | ||
} | ||
run().catch(console.dir); |
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
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 |
---|---|---|
|
@@ -312,3 +312,43 @@ the following: | |
E11000 duplicate key error index | ||
|
||
To learn more, see :manual:`Unique Indexes </core/index-unique>`. | ||
|
||
List Indexes | ||
------------ | ||
|
||
You can use the ``listIndexes()`` method to list all of the indexes | ||
for a collection. The `listIndexes() <{+api+}/classes/Collection.html#listIndexes>`__ method takes an | ||
optional `ListIndexesOptions | ||
<{+api+}/interfaces/ListIndexesOptions.html>`__ parameter. The ``listIndexes()`` method returns an | ||
object of type `ListIndexesCursor | ||
<{+api+}/classes/ListIndexesCursor.html>`__. | ||
|
||
The following code uses the ``listIndexes()`` method to list all the | ||
indexes in a collection: | ||
|
||
.. literalinclude:: /code-snippets/indexes/listIndexes.js | ||
:language: javascript | ||
rustagir marked this conversation as resolved.
Show resolved
Hide resolved
|
||
:dedent: | ||
:start-after: start listIndexes example | ||
:end-before: end listIndexes example | ||
|
||
List Search Indexes | ||
~~~~~~~~~~~~~~~~~~~ | ||
|
||
When connecting to {+mdb-server+} version 7.0 or later, you can use the new `listSearchIndexes() | ||
<https://mongodb.github.io/node-mongodb-native/Next/classes/Collection.html#listSearchIndexes>`__ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Investigating why the 5.6 docs don't cover this method |
||
method to return a cursor that contains the search indexes of a given | ||
collection. The ``listSearchIndexes()`` method takes an optional string parameter, ``name``, to | ||
return only the indexes with matching index names. It also takes an | ||
optional `aggregateOptions | ||
<https://mongodb.github.io/node-mongodb-native/Next/interfaces/AggregateOptions.html>`__ | ||
parameter. | ||
|
||
The following code uses the ``listSearchIndexes()`` method to list all | ||
the search indexes in the collection: | ||
|
||
.. literalinclude:: /code-snippets/indexes/listSearchIndexes.js | ||
:language: javascript | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add :dedent: |
||
:dedent: | ||
:start-after: start listSearchIndexes example | ||
:end-before: end listSearchIndexes example |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S: link to API docs for
listIndexes()
somewhere. same for below