neographikal
neographikal

Reputation: 93

Ravendb 2.5: query giving 0 results while it should be 1

I've got a problem with a query I can't figure out, I'm doing this query in code:

var userList = (from user in this.documentSession.Query<User>()
                            where user.FederatedUserIds[authenticatedClient.ProviderName] == authenticatedClient.UserInformation.Id
                            select user).ToList();

In this case the providername is facebook and the id = 100001103765630. The FederatedUserId's is a Dictionary.

Which results in this query to the server:

http://localhost:8080/indexes/dynamic/Users?&query=FederatedUserIds.facebook%3A100001103765630&pageSize=128

Which gives zero results, also from a query in the webbrowser:

{
    "Results": [],
    "Includes": [],
    "IsStale": false,
    "IndexTimestamp": "2013-08-24T14:52:44.0511623Z",
    "TotalResults": 0,
    "SkippedResults": 0,
    "IndexName": "Auto/Users/ByFederatedUserIds_facebook",
    "IndexEtag": "01000000-0000-0064-0000-000000000001",
    "ResultEtag": "2BD9AA1E-935A-FEDF-3636-FAB0F155ED9E",
    "Highlightings": {},
    "NonAuthoritativeInformation": false,
    "LastQueryTime": "2013-08-24T15:00:30.1200358Z",
    "DurationMilliseconds": 1
}

While I have a document that's like this in the database, so I expect 1 result instead of 0:

{
  "DisplayName": "neographikal",
  "RealName": "x",
  "Email": "x",
  "PictureUri": "x",
  "Roles": [
    "User"
  ],
  "ProfileImages": [],
  "FederatedUserIds": {
    "google": "x",
    "twitter": "x",
    "windowslive": "x",
    "linkedin": "x",
    "facebook": "100001103765630"
  }
}

The strange thing is, this has never bothered me before in this piece of code. Can somebody see where I'm doing this wrong?

Upvotes: 1

Views: 83

Answers (2)

neographikal
neographikal

Reputation: 93

Somehow, this was related to the indexes. Although it was a auto indexed query, deleting all the indexes on the server and rebooting the application solved the problem. I don't think this should have happened, but reproducing it seemed very difficult. If I can reproduce it in the feature, I'll try to investigate this further.

edit 01-09:

Found the problem and created a bug report: http://issues.hibernatingrhinos.com/issue/RavenDB-1334

Worked around it by creating a decent index:

public class UserByFederatedLoginIndex : AbstractIndexCreationTask<Core.Domain.User>
    {
        public UserByFederatedLoginIndex()
        {
            Map = users => from u in users
                           select new
                               {
                                   u.DisplayName,
                                   _ = u.FederatedUserIds.Select(x => CreateField("FederatedUserIds_"+x.Key, x.Value))
                               };
        }

Upvotes: 1

Matt Johnson-Pint
Matt Johnson-Pint

Reputation: 241450

I was going to say that you might have stale results, but I see that "IsStale": false.

The only other thing I see is that the query on the URL comes through as FederatedUserIds.facebook while the field name is going to be FederatedUserIds_facebook in the index. However, I tested this and it worked, so it appears that the . is translated to _ before the query executes. I'm not sure when this was added or if it's always been that way.

Note if you try to query with . in Raven Studio, it doesn't work there, but _ does.

What build version are you running? I tested on 2.5.2666 and it worked for me.

Upvotes: 1

Related Questions