MongoEngine / MongoEngine/mongoengine

Sparse false when unique_with

Open
#1,022 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Documentation Index
Dominant language
Python
Stars
4.3k
Forks
1.2k
Avg merge
4h 41m
Merged PRs (30d)
11

Description

I'm trying to create a field like this:

unique_for_owner = fields.StringField(unique_with=["owner"], required=False, sparse=True).

But i notice that index was created with sparse=False.

I dropped my collection and made a few tests, so i notice that when unique_with has a value the sparse always getting False.

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

Trace MongoEngine's field and index creation paths for a Python field using unique_with and sparse=True. Reproduce the reported case against MongoDB and compare the generated index options. Done means unique_with preserves sparse=True in the created index, with a regression test covering the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
mongodb, python
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.