MCPcopy Create free account
hub / github.com/mongodb/mongo-python-driver / create_indexes

Method create_indexes

pymongo/synchronous/collection.py:2178–2223  ·  view source on GitHub ↗

Create one or more indexes on this collection. >>> from pymongo import IndexModel, ASCENDING, DESCENDING >>> index1 = IndexModel([("hello", DESCENDING), ... ("world", ASCENDING)], name="hello_world") >>> index2 = IndexModel([("goodbye", D

(
        self,
        indexes: Sequence[IndexModel],
        session: Optional[ClientSession] = None,
        comment: Optional[Any] = None,
        **kwargs: Any,
    )

Source from the content-addressed store, hash-verified

2176 return client._retryable_read(func, self._read_preference_for(s), s, operation)
2177
2178 def create_indexes(
2179 self,
2180 indexes: Sequence[IndexModel],
2181 session: Optional[ClientSession] = None,
2182 comment: Optional[Any] = None,
2183 **kwargs: Any,
2184 ) -> list[str]:
2185 """Create one or more indexes on this collection.
2186
2187 >>> from pymongo import IndexModel, ASCENDING, DESCENDING
2188 >>> index1 = IndexModel([("hello", DESCENDING),
2189 ... ("world", ASCENDING)], name="hello_world")
2190 >>> index2 = IndexModel([("goodbye", DESCENDING)])
2191 >>> db.test.create_indexes([index1, index2])
2192 ["hello_world", "goodbye_-1"]
2193
2194 :param indexes: A list of :class:`~pymongo.operations.IndexModel`
2195 instances.
2196 :param session: a
2197 :class:`~pymongo.client_session.ClientSession`.
2198 :param comment: A user-provided comment to attach to this
2199 command.
2200 :param kwargs: optional arguments to the createIndexes
2201 command (like maxTimeMS) can be passed as keyword arguments.
2202
2203
2204
2205
2206 .. note:: The :attr:`~pymongo.collection.Collection.write_concern` of
2207 this collection is automatically applied to this operation.
2208
2209 .. versionchanged:: 3.6
2210 Added ``session`` parameter. Added support for arbitrary keyword
2211 arguments.
2212
2213 .. versionchanged:: 3.4
2214 Apply this collection's write concern automatically to this operation
2215 when connected to MongoDB >= 3.4.
2216 .. versionadded:: 3.0
2217
2218 .. _createIndexes: https://mongodb.com/docs/manual/reference/command/createIndexes/
2219 """
2220 common.validate_list("indexes", indexes)
2221 if comment is not None:
2222 kwargs["comment"] = comment
2223 return self._create_indexes(indexes, session, **kwargs)
2224
2225 @_csot.apply
2226 def _create_indexes(

Calls 1

_create_indexesMethod · 0.95