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

Throw error on wrong usage of where() #969

Closed
aldipower opened this issue Jun 18, 2012 · 1 comment
Closed

Throw error on wrong usage of where() #969

aldipower opened this issue Jun 18, 2012 · 1 comment

Comments

@aldipower
Copy link

Hi,
I had the following wrong query at a competition game:

    Model
    .where({uid: uid})  // Wrong syntax
    .where('address').exists(false)
    .limit(1)
    .desc('date') ...

I passed an object to the first where()-clause, but this wrong usage got completly ignored, in a silent error. As a result i got the newest document without an address, but accidently not matching the 'uid'. As next step I wrote the address of the user into a wrong document and could not match the win to the address anymore.

The correct syntax would be:

    Model
    .where('uid', uid)  // Correct syntax
    .where('address').exists(false)
    .limit(1)
    .desc('date') ...

This is tricky, because you can write this in a correct way
.find({uid: uid}),
but not this
.where({uid: uid}).

Maybe Mongoose could catch up such wrong usage by looking if the arguments are well formed and throw an error if neccesary.

@aheckmann
Copy link
Collaborator

yeah good catch. we'll get this in v3

On Jun 18, 2012, at 2:36 AM, Felix Gertzreply@reply.github.com wrote:

Hi,
I had the following wrong query at a competition game:

   Model
   .where({uid: uid})  // Wrong syntax
   .where('address').exists(false)
   .limit(1)
   .desc('date') ...

I passed an object to the first where()-clause, but this wrong usage got completly ignored, in a silent error. As a result i got the newest document without an address, but accidently not matching the 'uid'. As next step I wrote the address of the user into a wrong document and could not match the win to the address anymore.

The correct syntax would be:

   Model
   .where('uid', uid)  // Correct syntax
   .where('address').exists(false)
   .limit(1)
   .desc('date') ...

This is tricky, because you can write this in a correct way
.find({uid: uid}),
but not this
.where({uid: uid}).

Maybe Mongoose could catch up such wrong usage by looking if the arguments are well formed and throw an error if neccesary.


Reply to this email directly or view it on GitHub:
#969

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

2 participants