MCPcopy Index your code
hub / github.com/MongoEngine/mongoengine / _get_collection

Method _get_collection

mongoengine/document.py:210–236  ·  view source on GitHub ↗

Return the PyMongo collection corresponding to this document. Upon first call, this method: 1. Initializes a :class:`~pymongo.collection.Collection` corresponding to this document. 2. Creates indexes defined in this document's :attr:`meta` dictionary. T

(cls)

Source from the content-addressed store, hash-verified

208
209 @classmethod
210 def _get_collection(cls):
211 """Return the PyMongo collection corresponding to this document.
212
213 Upon first call, this method:
214 1. Initializes a :class:`~pymongo.collection.Collection` corresponding
215 to this document.
216 2. Creates indexes defined in this document's :attr:`meta` dictionary.
217 This happens only if `auto_create_index` is True.
218 """
219 if not hasattr(cls, "_collection") or cls._collection is None:
220 # Get the collection, either capped or regular.
221 if cls._meta.get("max_size") or cls._meta.get("max_documents"):
222 cls._collection = cls._get_capped_collection()
223 elif cls._meta.get("timeseries"):
224 cls._collection = cls._get_timeseries_collection()
225 else:
226 db = cls._get_db()
227 collection_name = cls._get_collection_name()
228 cls._collection = db[collection_name]
229
230 # Ensure indexes on the collection unless auto_create_index was
231 # set to False. Plus, there is no need to ensure indexes on slave.
232 db = cls._get_db()
233 if cls._meta.get("auto_create_index", True) and db.client.is_primary:
234 cls.ensure_indexes()
235
236 return cls._collection
237
238 @classmethod
239 def _get_capped_collection(cls):

Callers 15

saveMethod · 0.95
_save_createMethod · 0.95
_save_updateMethod · 0.95
_qsMethod · 0.95
__init__Method · 0.80
__init__Method · 0.80
switch_dbMethod · 0.80
switch_collectionMethod · 0.80
create_indexMethod · 0.80
ensure_indexesMethod · 0.80
get_classesMethod · 0.80
compare_indexesMethod · 0.80

Calls 6

_get_dbMethod · 0.80
ensure_indexesMethod · 0.80
getMethod · 0.45
_get_collection_nameMethod · 0.45