1

I have a problem that an index I've made when queried is throwing an exception :

Could not read value for property: Members

Here is the index :

public class GroupsNameIdIndex : AbstractIndexCreationTask<CommunityDocument, GroupsNameIdIndex.Result>
    {
        public class Result
        {
            public string CommunityId { get; set; }
            public string Id { get; set; }
            public string Name { get; set; }
            public IList<string> Members { get; set; }
        }

        public GroupsNameIdIndex()
        {
            Map = communities => from community in communities
               from newGroup in community.Groups
                select new
                {
                    CommunityId = community.Id.Replace("CommunityDocuments/", string.Empty),
                    newGroup.Id,
                    newGroup.Name,
                    newGroup.Members
                };
            StoreAllFields(FieldStorage.Yes);
        }
    }

This is the query :

 var groupResult = session
                .Query<GroupsNameIdIndex.Result, GroupsNameIdIndex>()
                .Where(x => x.CommunityId == info.Id)
                .AsProjection<GroupsNameIdIndex.Result>()
                .ToList();

I only have 1 group in the document with relevant Id and the Members node is an empty list, not null. When I manually populate it with a single string, then the query runs fine. Why are empty lists not allowed? If this is a restriction, it makes indexing pointless for me, because I will have a lot of empty lists that are just going to make the application fail everywhere.

edit: Adding the class in case that has something to do with it:

public class CommunityGroup
    {
        public CommunityGroup()
        {
            Members = new List<string>();
            MemberDetails = new List<MemberView>();
            MemberNames = new List<string>();
        }
        public string Id { get; set; }
        public string Name { get; set; }
        public string Slug { get; set; }
        public string Description { get; set; }
        public bool AdminOnly { get; set; }
        public bool NewsContribute { get; set; }
        public bool AutoGroup { get; set; }
        public int LowerAgeLimit { get; set; }
        public int UpperAgeLimit { get; set; }
        public string Gender { get; set; }
        public IList<string> Members { get; set; }
        public IList<string> MemberNames { get; set; }
        public IList<MemberView> MemberDetails { get; set; }
        public string RelatedCommunityId { get; set; }
        public string CreatedBy { get; set; }
        public bool SmartGroup { get; set; }
        public IList<SmartGroupRules> AndRules { get; set; }
        public IList<SmartGroupRules> OrRules { get; set; }
        public string ParentGroup { get; set; }
        public List<string> EntryGroups { get; set; }
        public bool Hidden { get; set; }
        public string ActivityType { get; set; }
        public List<string> AnyGroupList { get; set; }
        public List<string> AllGroupList { get; set; }
        public GroupType GroupType { get; set; }
    }

and here is the json of the group in the db

   "Groups": [
        {
            "Id": "5ja34tefoq7sfj",
            "Name": "new test",
            "Slug": "new-test",
            "Description": null,
            "AdminOnly": true,
            "NewsContribute": false,
            "AutoGroup": false,
            "LowerAgeLimit": 0,
            "UpperAgeLimit": 0,
            "Gender": null,
            "Members": [],
            "MemberNames": [],
            "MemberDetails": [],
            "RelatedCommunityId": null,
            "CreatedBy": "Activity",
            "SmartGroup": false,
            "AndRules": null,
            "OrRules": null,
            "ParentGroup": null,
            "EntryGroups": null,
            "Hidden": false,
            "ActivityType": null,
            "AnyGroupList": null,
            "AllGroupList": null,
            "GroupType": "Default"
        }
    ],
BMills
  • 881
  • 1
  • 10
  • 24
  • What is the full error? – Ayende Rahien May 15 '18 at 20:44
  • Inner exception is 'Error reading string. Unexpected token: StartObject.'. Stack trace is here: http://textuploader.com/dfx8m – BMills May 16 '18 at 11:33
  • which version of ravendb? – Embri May 16 '18 at 15:11
  • its version 3.5 – BMills May 16 '18 at 22:02
  • .AsProjection should be an extension method of previous versions of ravendb, i tried your code with .ProjectFromIndexFieldsInto and it works – Embri May 17 '18 at 07:21
  • ProjectFromIndexFieldsInto doesn't work either. I've added in the class and json for the data in case there's something wrong there. Just to reiterate, as soon as I add a string item into the 'Members' node, then it works. Very confusing issue. – BMills May 17 '18 at 09:34

0 Answers0