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

Already on GitHub? Sign in to your account

Array $gte, $gt, $lte, $lt only being cast as number #1101

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
2 participants
Contributor

dpatti commented Sep 15, 2012

This was originally added in 8bdc3d1 for #902. Trying a query similar to this:

model.find({ arr: { $gt: ObjectId("4fc78a59a885233f4b349bd9") } })

Works in the mongo shell, but gives this error in mongoose:

Invalid select() argument. Must be a string or object.

I assume, based on the title, that the problem is that it is being cast as a number instead of using castForQuery as everything else is.

Collaborator

aheckmann commented Sep 11, 2012

odd that the errr message refers to an invalid select. should just bypass casting I guess

Contributor

dpatti commented Sep 11, 2012

No, shit, I'm sorry. That message is not related at all. We were previously using v2 where you could do a select with ['attr1', 'att2'] notation, and that was the error. I just found out a few minutes ago, but I wrote this initial ticket while I did not have access to my code. Sorry for the confusion!

That said, I believe the initial problem is still present.

Collaborator

aheckmann commented Sep 11, 2012

ok, thanks for reporting. i'll be busy for the next week or so. if you have time to submit a patch in the meantime that would be awesome.

Contributor

dpatti commented Sep 14, 2012

I am finishing up some work myself, but I will take a look at a getting a
patch together tomorrow. Are you looking for unit tests as well?

On Tue, Sep 11, 2012 at 1:17 PM, Aaron Heckmann notifications@github.comwrote:

ok, thanks for reporting. i'll be busy for the next week or so. if you
have time to submit a patch in the meantime that would be awesome.


Reply to this email directly or view it on GitHubhttps://github.com/LearnBoost/mongoose/issues/1101#issuecomment-8465350.

Fix query casting for inequalities in arrays
In 8bdc3d1, support for inequalities $gt, $gte, $lt, and $lte were added for
queries involving arrays, but the values given to queries were always cast to
numbers. This change uses castForQuery so that it is cast to the attribute's
type specified in the schema.

closes #1101
Contributor

dpatti commented Sep 15, 2012

Let me know if that test is sufficient enough. I didn't think copying and pasting the same thing four times would have been very neat, and I haven't seen any use of test in for loops, so I just went with this.

@aheckmann aheckmann closed this in 10de061 Sep 18, 2012

Collaborator

aheckmann commented Sep 18, 2012

merged. thanks a bunch!

aheckmann added a commit that referenced this pull request Sep 18, 2012

Fix query casting for inequalities in arrays
In 8bdc3d1, support for inequalities $gt, $gte, $lt, and $lte were added for
queries involving arrays, but the values given to queries were always cast to
numbers. This change uses castForQuery so that it is cast to the attribute's
type specified in the schema.

closes #1101
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment