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

Method generate

mongoengine/fields.py:2118–2132  ·  view source on GitHub ↗

Generate and Increment the counter

(self)

Source from the content-addressed store, hash-verified

2116 super().__init__(*args, **kwargs)
2117
2118 def generate(self):
2119 """
2120 Generate and Increment the counter
2121 """
2122 sequence_name = self.get_sequence_name()
2123 sequence_id = f"{sequence_name}.{self.name}"
2124 collection = get_db(alias=self.db_alias)[self.collection_name]
2125
2126 counter = collection.find_one_and_update(
2127 filter={"_id": sequence_id},
2128 update={"$inc": {"next": 1}},
2129 return_document=ReturnDocument.AFTER,
2130 upsert=True,
2131 )
2132 return self.value_decorator(counter["next"])
2133
2134 def set_next_value(self, value):
2135 """Helper method to set the next sequence value"""

Callers 4

__get__Method · 0.95
__set__Method · 0.95
to_pythonMethod · 0.95
to_mongoMethod · 0.80

Calls 2

get_sequence_nameMethod · 0.95
get_dbFunction · 0.90

Tested by

no test coverage detected