@@ -61,6 +61,25 @@ appropriate for your application, see the MongoDB server documentation on
61
61
:manual:`Indexing Strategies </applications/indexes>` and
62
62
:manual:`Data Modeling and Indexes </core/data-model-operations/#data-model-indexes>`.
63
63
64
+ List Indexes
65
+ ~~~~~~~~~~~~
66
+
67
+ You can use the ``listIndexes()`` method to list all of the indexes
68
+ for a collection. The `listIndexes() <{+api+}/classes/Collection.html#listIndexes>`__ method takes an
69
+ optional `ListIndexesOptions
70
+ <{+api+}/interfaces/ListIndexesOptions.html>`__ parameter. The ``listIndexes()`` method returns an
71
+ object of type `ListIndexesCursor
72
+ <{+api+}/classes/ListIndexesCursor.html>`__.
73
+
74
+ The following code uses the ``listIndexes()`` method to list all the
75
+ indexes in a collection:
76
+
77
+ .. literalinclude:: /code-snippets/indexes/listIndexes.js
78
+ :language: javascript
79
+ :dedent:
80
+ :start-after: start listIndexes example
81
+ :end-before: end listIndexes example
82
+
64
83
Index Types
65
84
-----------
66
85
@@ -313,42 +332,97 @@ the following:
313
332
314
333
To learn more, see :manual:`Unique Indexes </core/index-unique>`.
315
334
316
- List Indexes
317
- ------------
335
+ Search Indexes
336
+ --------------
318
337
319
- You can use the ``listIndexes()`` method to list all of the indexes
320
- for a collection. The `listIndexes() <{+api+}/classes/Collection.html#listIndexes>`__ method takes an
321
- optional `ListIndexesOptions
322
- <{+api+}/interfaces/ListIndexesOptions.html>`__ parameter. The ``listIndexes()`` method returns an
323
- object of type `ListIndexesCursor
324
- <{+api+}/classes/ListIndexesCursor.html>`__.
338
+ Atlas Search is a feature that allows you to perform full-text
339
+ searches. To learn more, see the :ref:`Atlas Search <fts-top-ref>`
340
+ documentation.
325
341
326
- The following code uses the ``listIndexes()`` method to list all the
327
- indexes in a collection:
342
+ Before you can perform a search on an Atlas collection, you must first
343
+ create an Atlas Search index on the collection. An Atlas Search
344
+ index is a data structure that categorizes data in a searchable format.
328
345
329
- .. literalinclude:: /code-snippets/indexes/listIndexes.js
346
+ Starting in version 5.7 of the {+driver-short+}, you can manage your
347
+ Search indexes using the following methods:
348
+
349
+ - ``createSearchIndex()``
350
+ - ``createSearchIndexes()``
351
+ - ``listSearchIndexes()``
352
+ - ``updateSearchIndex()``
353
+ - ``dropSearchIndex()``
354
+
355
+ The following sections provide example code using each of the preceding
356
+ methods to manage Search indexes.
357
+
358
+ Create Search Indexes
359
+ ~~~~~~~~~~~~~~~~~~~~~
360
+
361
+ You can use the `createSearchIndex()
362
+ <{+api+}/classes/Collection.html#createSearchIndex>`__ and
363
+ `createSearchIndexes() <{+api+}/classes/Collection.html#createSearchIndexes>`__
364
+ methods to create new Search indexes.
365
+
366
+ The following code shows how to
367
+ use the ``createSearchIndex()`` method to create an index called
368
+ ``search1``:
369
+
370
+ .. literalinclude:: /code-snippets/indexes/searchIndexes.js
330
371
:language: javascript
331
372
:dedent:
332
- :start-after: start listIndexes example
333
- :end-before: end listIndexes example
373
+ :start-after: start createSearchIndex example
374
+ :end-before: end createSearchIndex example
334
375
335
376
List Search Indexes
336
377
~~~~~~~~~~~~~~~~~~~
337
378
338
- When connecting to {+mdb-server+} version 7.0 or later, you can use the new `listSearchIndexes()
339
- <https://mongodb.github.io/node-mongodb-native/Next /classes/Collection.html#listSearchIndexes>`__
379
+ You can use the `listSearchIndexes()
380
+ <{+api+} /classes/Collection.html#listSearchIndexes>`__
340
381
method to return a cursor that contains the search indexes of a given
341
- collection. The ``listSearchIndexes()`` method takes an optional string parameter, ``name``, to
342
- return only the indexes with matching index names. It also takes an
343
- optional `aggregateOptions
344
- <https://mongodb.github.io/node-mongodb-native/Next/interfaces/AggregateOptions.html>`__
345
- parameter.
382
+ collection. The ``listSearchIndexes()`` method takes an optional string
383
+ parameter, ``name``, to return only the indexes with matching index
384
+ names. It also takes an optional `aggregateOptions
385
+ <{+api+}/interfaces/AggregateOptions.html>`__ parameter.
346
386
347
- The following code uses the ``listSearchIndexes()`` method to list all
348
- the search indexes in the collection:
387
+ The following code uses the ``listSearchIndexes()`` method to list the
388
+ Search indexes in a collection:
349
389
350
390
.. literalinclude:: /code-snippets/indexes/listSearchIndexes.js
351
391
:language: javascript
352
392
:dedent:
353
393
:start-after: start listSearchIndexes example
354
- :end-before: end listSearchIndexes example
394
+ :end-before: end listSearchIndexes example
395
+
396
+ Update Search Indexes
397
+ ~~~~~~~~~~~~~~~~~~~~~
398
+
399
+ You can use the `updateSearchIndex()
400
+ <{+api+}/classes/Collection.html#updateSearchIndex>`__ method to update a Search
401
+ index.
402
+
403
+ The following code shows how to
404
+ use the ``updateSearchIndex()`` method to update an index called
405
+ ``search1`` to specify a string type for the ``description`` field:
406
+
407
+ .. literalinclude:: /code-snippets/indexes/searchIndexes.js
408
+ :language: javascript
409
+ :dedent:
410
+ :start-after: start dropSearchIndex example
411
+ :end-before: end dropSearchIndex example
412
+
413
+ Remove Search Indexes
414
+ ~~~~~~~~~~~~~~~~~~~~~
415
+
416
+ You can use the `dropSearchIndex()
417
+ <{+api+}/classes/Collection.html#dropSearchIndex>`__ method to remove a Search
418
+ index.
419
+
420
+ The following code shows how to
421
+ use the ``dropSearchIndex()`` method to remove an index called
422
+ ``search1``:
423
+
424
+ .. literalinclude:: /code-snippets/indexes/searchIndexes.js
425
+ :language: javascript
426
+ :dedent:
427
+ :start-after: start dropSearchIndex example
428
+ :end-before: end dropSearchIndex example
0 commit comments