Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Querying too restrictive (and inconsistent with MongoDB shell) #332

Closed
wojcikstefan opened this issue May 23, 2013 · 5 comments
Closed

Querying too restrictive (and inconsistent with MongoDB shell) #332

wojcikstefan opened this issue May 23, 2013 · 5 comments
Milestone

Comments

@wojcikstefan
Copy link
Member

Mongo shell:

> db.lead.find({ status: 'potential', status: 'potential', status: 'active' }).count()
1356
> db.lead.find({ status: 'active' }).count()
1356

MongoEngine

> Lead.objects.filter(status='potential').filter(status='potential').filter(status='active').count()
InvalidQueryError: Duplicate query conditions: status

Shouldn't these be consistent (i.e. filter by the last argument)? I understand that generally you don't wanna end up with this type of query, but sometimes it's very hard/impossible. Also, there's no easy way to "unset" a query parameter, so if you get a filtered set, it basically means you're restricted to parameters that haven't been used before.

This is even more important in ver. 0.8, since the queryset cloning finally works as expected.

@wojcikstefan
Copy link
Member Author

Maybe the example above is unfortunate, since it's basically JS that transforms { a: 'a', a: 'b' } into { a: 'b' }, but I still think the duplicate query issue could be solved better.

@rozza
Copy link
Contributor

rozza commented Jun 4, 2013

Dealing with in #333

@Hugh-wong
Copy link

I'm sorry for that I know this issue is closed, but I think this issue is not fixed actually.
https://groups.google.com/forum/#!msg/mongoengine-users/FiuFQRQilfE/u1M0RrqrhaIJ
the link above referenced that _all query for the listfield, but actually I got the following problems:

Foo.objects.filter(bar__contains = 'something', bar__contains = 'someother')
↑ this will throw the duplicate query error
↓but this will be fine
Foo.objects.filter(bar__contains = 'something', bar__icontains = 'someother')
Somehow, I think that this condition is quite useful when I want to find the document which it's 'bar' field contains both the 'something' and the 'someother'

currently, I have commented the mongoengine/queryset/vistor.py 53~58, and test fine.

Hope my poor English wont cause your trouble.

@wojcikstefan
Copy link
Member Author

Hi @Hugh-wong! Foo.objects.filter(bar__contains = 'something', bar__contains = 'someother') is simply an incorrect syntax in Python. Kwargs can't be repeated.

@Hugh-wong
Copy link

@wojcikstefan
Thanks, I got it, realize that even I can query with it, the result is just queried with the last key-value pair.
before that, I was wondering why db.foo.find({'bar':'a', bar:'b'}) works fine, the result is just queried with {'bar':'b'}.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants