Skip to content

Conversation

freeeve
Copy link
Contributor

@freeeve freeeve commented Jan 25, 2012

This adds $and support to QueryBuilder, along with a simple test. Based on the $or function.

bwmcadams pushed a commit that referenced this pull request Jan 25, 2012
This adds $and support to QueryBuilder, along with a simple test.
@bwmcadams bwmcadams merged commit 94a5fda into mongodb:master Jan 25, 2012
@scotthernandez
Copy link
Contributor

It is probably good to only add $and if there are children with the same name, otherwise $and is not needed, will bloat the query, and it may cause performance issues.

@alaz
Copy link

alaz commented Jan 27, 2012

I had initially implemented something alike in Subset, but have finally decided to leave the explicit logic (e.g. it's the developer who decides) because this "automated behavior" should be ideally more complex: e.g. if any of the arguments already contains $and it should be unfold and the new $and constructed with all the arrays merged.

@scotthernandez
Copy link
Contributor

That is true, it is up to programmer to use the method but I'd be afraid they will use it logically without thinking about the ramifications of using lots of "and"s together. Perhaps this is best dealt with in (java)docs and we can just wait to see if the problems arise.

@freeeve
Copy link
Contributor Author

freeeve commented Jan 27, 2012

There's no reason it can't check for other $and operators in the query, and then check for keys with the same name, if that's better behavior. I didn't realize it would perform worse so I just did the naive/safe way. I agree with Scott that it would be misleading--a lot of people use query builders exclusively and it should work in the best way possible. I'll submit another patch when I can get to it.

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

Successfully merging this pull request may close these issues.

4 participants