Creates the given indexes if required. :param keys: a single index key or a list of index keys (to construct a multi-field index); keys may be prefixed with a **+** or a **-** to determine the index ordering :param background: Allows index creation in the bac
(cls, keys, background=False, **kwargs)
| 877 | |
| 878 | @classmethod |
| 879 | def create_index(cls, keys, background=False, **kwargs): |
| 880 | """Creates the given indexes if required. |
| 881 | |
| 882 | :param keys: a single index key or a list of index keys (to |
| 883 | construct a multi-field index); keys may be prefixed with a **+** |
| 884 | or a **-** to determine the index ordering |
| 885 | :param background: Allows index creation in the background |
| 886 | """ |
| 887 | index_spec = cls._build_index_spec(keys) |
| 888 | index_spec = index_spec.copy() |
| 889 | fields = index_spec.pop("fields") |
| 890 | index_spec["background"] = background |
| 891 | index_spec.update(kwargs) |
| 892 | |
| 893 | return cls._get_collection().create_index(fields, **index_spec) |
| 894 | |
| 895 | @classmethod |
| 896 | def ensure_indexes(cls): |