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

UserStore.FindAsync Incorrect Query Logic #18

Open
kingdango opened this issue Jun 24, 2014 · 0 comments
Open

UserStore.FindAsync Incorrect Query Logic #18

kingdango opened this issue Jun 24, 2014 · 0 comments

Comments

@kingdango
Copy link

Thanks for the work on this. I found a bug while I was "borrowing" your existing work and thought I would help. I don't plan to use this library verbatim at this point so instead of submitting a commit I will just comment below:

The UserStore FindAsync implementation is incorrect. Although the query will probably match the user most of the time it will yield the wrong user in some cases. It is also not as performant as the suggested change.

user = _users
    .FindOne(Query.And(Query.EQ("Logins.LoginProvider", login.LoginProvider), 
        Query.EQ("Logins.ProviderKey", login.ProviderKey)));

Should be changed to use ElemMatch which actually compares two values of the same element of an array instead of two distinct properties of any of the array values.

var user = _users.FindOne(
                Query<TUser>.ElemMatch(i => i.Logins, i => Query.And(
                    Query<UserLoginInfo>.EQ(loginRow => loginRow.LoginProvider, login.LoginProvider),
                    Query<UserLoginInfo>.EQ(loginRow => loginRow.ProviderKey, login.ProviderKey))));

I haven't tested the change but I do know ElemMatch is what should be used for a query on multiple properties of a single array element. Wanted to let you know before I moved on. Thanks again for the work on this!

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

1 participant