Create an Index instance. For use with :meth:`~pymongo.asynchronous.collection.AsyncCollection.create_indexes` and :meth:`~pymongo.collection.Collection.create_indexes`. Takes either a single key or a list containing (key, direction) pairs or keys. If no direction is given
(self, keys: _IndexKeyHint, **kwargs: Any)
| 723 | __slots__ = ("__document",) |
| 724 | |
| 725 | def __init__(self, keys: _IndexKeyHint, **kwargs: Any) -> None: |
| 726 | """Create an Index instance. |
| 727 | |
| 728 | For use with :meth:`~pymongo.asynchronous.collection.AsyncCollection.create_indexes` and :meth:`~pymongo.collection.Collection.create_indexes`. |
| 729 | |
| 730 | Takes either a single key or a list containing (key, direction) pairs |
| 731 | or keys. If no direction is given, :data:`~pymongo.ASCENDING` will |
| 732 | be assumed. |
| 733 | The key(s) must be an instance of :class:`str`, and the direction(s) must |
| 734 | be one of (:data:`~pymongo.ASCENDING`, :data:`~pymongo.DESCENDING`, |
| 735 | :data:`~pymongo.GEO2D`, :data:`~pymongo.GEOSPHERE`, |
| 736 | :data:`~pymongo.HASHED`, :data:`~pymongo.TEXT`). |
| 737 | |
| 738 | Valid options include, but are not limited to: |
| 739 | |
| 740 | - `name`: custom name to use for this index - if none is |
| 741 | given, a name will be generated. |
| 742 | - `unique`: if ``True``, creates a uniqueness constraint on the index. |
| 743 | - `background`: if ``True``, this index should be created in the |
| 744 | background. |
| 745 | - `sparse`: if ``True``, omit from the index any documents that lack |
| 746 | the indexed field. |
| 747 | - `bucketSize`: for use with geoHaystack indexes. |
| 748 | Number of documents to group together within a certain proximity |
| 749 | to a given longitude and latitude. |
| 750 | - `min`: minimum value for keys in a :data:`~pymongo.GEO2D` |
| 751 | index. |
| 752 | - `max`: maximum value for keys in a :data:`~pymongo.GEO2D` |
| 753 | index. |
| 754 | - `expireAfterSeconds`: <int> Used to create an expiring (TTL) |
| 755 | collection. MongoDB will automatically delete documents from |
| 756 | this collection after <int> seconds. The indexed field must |
| 757 | be a UTC datetime or the data will not expire. |
| 758 | - `partialFilterExpression`: A document that specifies a filter for |
| 759 | a partial index. |
| 760 | - `collation`: An instance of :class:`~pymongo.collation.Collation` |
| 761 | that specifies the collation to use. |
| 762 | - `wildcardProjection`: Allows users to include or exclude specific |
| 763 | field paths from a `wildcard index`_ using the { "$**" : 1} key |
| 764 | pattern. Requires MongoDB >= 4.2. |
| 765 | - `hidden`: if ``True``, this index will be hidden from the query |
| 766 | planner and will not be evaluated as part of query plan |
| 767 | selection. Requires MongoDB >= 4.4. |
| 768 | |
| 769 | See the MongoDB documentation for a full list of supported options by |
| 770 | server version. |
| 771 | |
| 772 | :param keys: a single key or a list containing (key, direction) pairs |
| 773 | or keys specifying the index to create. |
| 774 | :param kwargs: any additional index creation |
| 775 | options (see the above list) should be passed as keyword |
| 776 | arguments. |
| 777 | |
| 778 | .. versionchanged:: 3.11 |
| 779 | Added the ``hidden`` option. |
| 780 | .. versionchanged:: 3.2 |
| 781 | Added the ``partialFilterExpression`` option to support partial |
| 782 | indexes. |
nothing calls this directly
no test coverage detected