MongoEngine / MongoEngine/mongoengine
Allow restricting the fields fetched when using LazyReferenceField
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.3k
- Forks
- 1.2k
- Avg merge
- 4h 41m
- Merged PRs (30d)
- 11
Description
Suppose we have the following document structure.
class Bar(Document):
a_simple_field = StringField()
a_huge_field = BinaryField()
class Foo(Document):
some_info = StringField()
bar = LazyReferenceField('Bar')
I would like to be able to call fetch() on the bar field of Foo without fetching a_huge_field from Bar. Maybe we can do something like:
a_bar = a_foo.bar.fetch(fields={'a_simple_field': 1})
another_bar = another_foo.bar.fetch(fields={'a_huge_field': 0})
Which follows the fields pattern: https://github.com/MongoEngine/mongoengine/blob/4caa58b9ec3afc856a7c05a2cdca9152b2c29e5f/mongoengine/queryset/base.py#L950.
I've opened a pull request with a possible implementation.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the LazyReferenceField.fetch entry point and compare the requested fields pattern in queryset/base.py around line 950. Review pull request #2037 for the existing implementation and its coverage; done means the proposed fetch(fields=...) behavior is implemented and verified without retrieving excluded fields.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mongodb, python
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 25/100