MongoEngine / MongoEngine/mongoengine

Allow restricting the fields fetched when using LazyReferenceField

Open
#2,036 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.