Skip to content

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
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions source/code-snippets/indexes/listIndexes.js
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("The indexes in the collection are: ");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S: Per the style guide, we do not introduce lists with fragment sentences. (also applies to other file)

Perhaps something like this would be better:

Suggested change
console.log("The indexes in the collection are: ");
console.log("Existing indexes:\n");

for(const doc in result){
console.log(doc);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S: this line should be indented. Maybe re-run the formatter on your code? Also applies to other snippet

}
// end listIndexes example
} finally {
await client.close();
}
}
run().catch(console.dir);
27 changes: 27 additions & 0 deletions source/code-snippets/indexes/listSearchIndexes.js
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("The search indexes in the collection are: ");
for(const doc in result){
console.log(doc);
}
// end listSearchIndexes example
} finally {
await client.close();
}
}
run().catch(console.dir);
4 changes: 3 additions & 1 deletion source/fundamentals/crud/read-operations/cursor.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ The following functions directly return cursors:

- ``Collection.listIndexes()``

- ``Collection.listSearchIndexes()``

- ``Db.aggregate()``

- ``Db.listCollections()``
Expand Down Expand Up @@ -113,7 +115,7 @@ through results rather than returning all documents at once.
:language: javascript
:start-after: start fetchAll cursor example
:end-before: end fetchAll cursor example

Stream API
~~~~~~~~~~

Expand Down
39 changes: 39 additions & 0 deletions source/fundamentals/indexes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,42 @@ the following:
E11000 duplicate key error index

To learn more, see :manual:`Unique Indexes </core/index-unique>`.

List Indexes
~~~~~~~~~~~~
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S: make this a header one level up, as the section is not an index type


The ``listIndexes()`` method allows you to list all the indexes'
information in the collection. The ``listIndexes()`` method takes an
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The ``listIndexes()`` method allows you to list all the indexes'
information in the collection. The ``listIndexes()`` method takes an
You can use the ``listIndexes()`` method to list all of the indexes
for a collection. The ``listIndexes()`` method takes an

optional parameter, `ListIndexesOptions
<{+api+}/interfaces/ListIndexesOptions.html>`__, to set optional
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
optional parameter, `ListIndexesOptions
<{+api+}/interfaces/ListIndexesOptions.html>`__, to set optional
optional `ListIndexesOptions <{+api+}/interfaces/ListIndexesOptions.html>`__ parameter to set optional

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S; remove this clause of the sentence

settings for the method. The ``listIndexes()`` method returns an
object of type `ListIndexesCursor
<{+api+}/classes/ListIndexesCursor.html>`__.

The following example uses the ``listIndexes()`` method to list all the
indexes' information in the collection.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S: change wording to match above suggestion from the first sentence


.. literalinclude:: /code-snippets/indexes/listIndexes.js
:language: javascript
: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>`__
Copy link
Collaborator

Choose a reason for hiding this comment

The 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 for the current
collection. The ``listSearchIndexes()`` method takes an optional string parameter, ``name``, to
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: What does current mean in this context? Can't you just call the method on whatever collection you want?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, thank you!

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 example uses the ``listSearchIndexes()`` method to list all
the search indexes in the collection.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The following example uses the ``listSearchIndexes()`` method to list all
the search indexes in the collection.
The following code uses the ``listSearchIndexes()`` method to list all
the search indexes in the collection:


.. literalinclude:: /code-snippets/indexes/listSearchIndexes.js
:language: javascript
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add :dedent:

:start-after: start listSearchIndexes example
:end-before: end listSearchIndexes example