RavenDB4 : Id property in Fanout Index Result returns wrong value

35 views
Skip to first unread message

oru malayali

unread,
Mar 15, 2018, 6:39:21 PM3/15/18
to RavenDB - 2nd generation document database
Hi,
I have a fanout index and the resulting documents have an Id property. Now, I assign the inner list property.Id to the Result.Id, but it overwrites the value with the main document Id.
Below is the simulation of my issue:
Do you have any constraints on the fanout index result like the property should not be named Id?

Documents:
    public class SimpleTestDocument
    {
        public string Id { get; set; }
        public string Comment { get; set; }
    }

    public class Level2SimpleTestDocument
    {
        private readonly List<SimpleTestDocument> _simpleTestDocumentList = new List<SimpleTestDocument>();

        public string Id { get; set; }

        public IEnumerable<SimpleTestDocument> SimpleTestDocumentList => this._simpleTestDocumentList.AsEnumerable();

        public void AddSimpleTestDocument(SimpleTestDocument doc)
        {
            if (doc != null)
            {
                this._simpleTestDocumentList.Add(doc);
            }
        }
    }

Index:
    public class FanOutIdTestIndex : AbstractIndexCreationTask<Level2SimpleTestDocument>
    {
        public FanOutIdTestIndex()
        {
            this.Map = documents => from doc in documents
                from innerDoc in doc.SimpleTestDocumentList
                select new Result
                {
                    Id = innerDoc.Id,
                    InnerDocId = innerDoc.Id,
                    MainDocId = doc.Id
                };

            this.StoreAllFields(FieldStorage.Yes);
        }

        public class Result
        {
            public string Id { get; set; }
            public string InnerDocId { get; set; }
            public string MainDocId { get; set; }
        }
    }

Test:
        [Fact]
        public void GivenAFanOutIndex_WhenIdPropertyInIndexResultIsAssignedAValue_ObjectReturnedByQueryShouldHaveAssignedValue()
        {
            using (var session = this._dbStore.OpenSession())
            {
                var testDoc = new Level2SimpleTestDocument
                {
                    Id = session.GetDocumentId(typeof(Level2SimpleTestDocument), 123),
                };
                testDoc.AddSimpleTestDocument(new SimpleTestDocument { Id = "SimpleTestDocuments/123" });
                testDoc.AddSimpleTestDocument(new SimpleTestDocument { Id = "SimpleTestDocuments/124" });

                session.Store(testDoc);
                session.SaveChanges();
            }
            using (var session = this._dbStore.OpenSession())
            {
                var query = session.Query<FanOutIdTestIndex.Result, FanOutIdTestIndex>()
                    .ProjectInto<FanOutIdTestIndex.Result>().ToList();

                query.ForEach(d => Assert.Equal(d.InnerDocId, d.Id));
            }
        }

Sorry for the trouble, but I have a couple of indexes where I have Id in the index result. Also, I think this was not an issue in RavenDB 3.0.

Thanks,
Lokesh

Paweł Pekról

unread,
Mar 16, 2018, 5:22:35 AM3/16/18
to RavenDB - 2nd generation document database
Hi,

the Client API is detecting that the 'Id' property 'FanOutIdTestIndex.Result' is an IdentityProperty using store.Conventions.FindIdentityProperty convention, so the RQL that is sent to the Server looks like this:

from index 'FanOutIdTestIndex' select id() as Id, InnerDocId, MainDocId

I would suggest to avoid using 'Id' inside the Index.

P.

oru malayali

unread,
Mar 16, 2018, 9:48:45 AM3/16/18
to rav...@googlegroups.com
Hi Pawel,
I see. But this used to be working in 3.0, I mean the Id in the Index.

I have questions here, but since I don't know the underlying architecture yet, I think the questions might turn out to be very stupid. For now, I will use your suggestion. 
Do you think you might be able to fix this later?

Thanks,
Lokesh

--
You received this message because you are subscribed to a topic in the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ravendb/Krhti1SBEhA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ravendb+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Oren Eini (Ayende Rahien)

unread,
Mar 18, 2018, 3:41:49 AM3/18/18
to ravendb
The actual problem is that this is the same type as the root collection, so we don't know what you are meant to do here.


Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.

oru malayali

unread,
Mar 19, 2018, 9:46:11 AM3/19/18
to rav...@googlegroups.com
I see. Sure. I think, I might have misunderstood the concept of Index. I thought, when I ask to store the values in Index, the computed values are actually stored separately. I didn't know the identity property is inherited and cannot be overriden.

Thanks.
Reply all
Reply to author
Forward
0 new messages