MongoEngine / MongoEngine/mongoengine

not__match__nin is not working

Open
#1,034 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I have DB like this

{ "_id" : ObjectId("558233a3f89235c3ef7e2985"), "list" : [ "1", "2", "3", "4", "5" ] }
{ "_id" : ObjectId("558233abf89235c3ef7e2986"), "list" : [ "6", "2", "3", "4", "5" ] }

and raw query is:

> db.chara.find({list: {$not: {$elemMatch: {$nin: ["2", "3", "4", "5", "6", "7"]}}}})
{ "_id" : ObjectId("558233abf89235c3ef7e2986"), "list" : [ "6", "2", "3", "4", "5" ] }

But when I use this query, it may be ignore and all record be showed

chara.objects.filter(list__not__match__nin=["2", "3", "4", "5", "6", "7"])

However, this work perfectly:

chara.objects.filter(__raw__={"compare_targets": {"$not": {"$elemMatch": {"$nin": ["2", "3", "4", "5", "6", "7"]}}}})

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 reproducing the list__not__match__nin filter from the issue and compare its generated query with the working raw query. Trace how this filter is translated into MongoDB operators, then verify that the filtered results match the raw query example with a focused regression test.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.