MongoEngine / MongoEngine/mongoengine

add parameter `field_name` to in_bulk queryset method

Open
#2,550 1 comment 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

the django ORM has a similar function to the existing in_bulk method.

https://docs.djangoproject.com/en/3.2/ref/models/querysets/#in-bulk

https://github.com/MongoEngine/mongoengine/blob/96802599045432274481b4ed9fcc4fad4ce5f89b/mongoengine/queryset/base.py#L722-L745

It also provides an additional field_name parameter, which makes it easy to load objects in bulk not only by their IDs, but also, by any field. For example, someone might want to bulk load users by their usernames.

It would be convenient if mongoengine also provided the same feature.
What do you think of this idea? I'd love to make a PR if you're okay with this.

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 by reading mongoengine/queryset/base.py around the in_bulk implementation referenced in the issue, then compare it with Django's in_bulk documentation and the linked MongoEngine example. Add support for an optional field_name so bulk loading can use fields such as usernames as well as IDs, and verify the existing ID behavior remains intact.

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
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.