Return a query dict that can be used to fetch this document. Most of the time the dict is a simple PK lookup, but in case of a sharded collection with a compound shard key, it can contain a more complex query. Note that the dict returned by this method uses MongoEng
(self)
| 623 | |
| 624 | @property |
| 625 | def _object_key(self): |
| 626 | """Return a query dict that can be used to fetch this document. |
| 627 | |
| 628 | Most of the time the dict is a simple PK lookup, but in case of |
| 629 | a sharded collection with a compound shard key, it can contain a more |
| 630 | complex query. |
| 631 | |
| 632 | Note that the dict returned by this method uses MongoEngine field |
| 633 | names instead of PyMongo field names (e.g. "pk" instead of "_id", |
| 634 | "some__nested__field" instead of "some.nested.field", etc.). |
| 635 | """ |
| 636 | select_dict = {"pk": self.pk} |
| 637 | shard_key = self.__class__._meta.get("shard_key", tuple()) |
| 638 | for k in shard_key: |
| 639 | val = self |
| 640 | field_parts = k.split(".") |
| 641 | for part in field_parts: |
| 642 | val = getattr(val, part) |
| 643 | select_dict["__".join(field_parts)] = val |
| 644 | return select_dict |
| 645 | |
| 646 | def update(self, **kwargs): |
| 647 | """Performs an update on the :class:`~mongoengine.Document` |