Fetch real Id field casing with ProjectFromIndexFieldsInto

51 views
Skip to first unread message

Pierre-Yves Dezaunay

unread,
Dec 17, 2017, 4:38:09 AM12/17/17
to rav...@googlegroups.com

Hi,

I am using a map index to fetch a few fields of some documents. It returns document Id lower case, which is what to expect from RavenDb.

Sometimes, I need to get the whole document and not only the indexed fields. I am using ProjectFromIndexFieldsInto to fetch it. In this case, the document must be loaded from disk, and raven should fetch the real ID, with its actual casing. But it still returns it lower case.

I cannot find any configuration to require to fetch some fields from document rather than index using ProjectFromIndexFieldsInto.

e.g. :
here is my index

public class DocumentIndex : AbstractIndexCreationTask<Document>
   
{
       
public DocumentIndex()
       
{
           
this.Map = items =>
               
from x in items
               
select new Projection
               
{
                   
Id = x.Id,
                   
Foo = x.Foo,
                   
Bar = x.Foo + "bar",
               
};
       
}

       
public class Projection
       
{
           
public string Id { get; set; }
           
public string Foo { get; set; }
           
public string Bar { get; set; }
       
}
   
}



I then get my documents using :

 string[] baz;
 
var query = this.Query<DocumentIndex.Projection, DocumentIndex>().Where(x=>x.Bar.In(baz));
 
var query2 = query.ProjectFromIndexFieldsInto<Document>();
 
var items = query2.Skip(offset).Take(pageSize).ToList();

I want to get the real Id (not lower cased) in my items collection.


Is there any way to do this ?

Regards,
PY

Oren Eini (Ayende Rahien)

unread,
Dec 17, 2017, 4:44:26 AM12/17/17
to ravendb
What build are you using?

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.
For more options, visit https://groups.google.com/d/optout.

Pierre-Yves

unread,
Dec 18, 2017, 5:29:41 AM12/18/17
to RavenDB - 2nd generation document database

I was using the following builds :
  • Server Build #30115
  • Client Build #35241
I just install the last stable update :
  • Server Build #35215
  • Client Build #35241
It do not solve the problem.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.

Oren Eini (Ayende Rahien)

unread,
Dec 18, 2017, 6:49:42 AM12/18/17
to ravendb
Call Store() on the Id for the document.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.

Pierre-Yves

unread,
Dec 18, 2017, 8:45:07 AM12/18/17
to RavenDB - 2nd generation document database

I tried to add the following loop after getting entities.

            string[] baz;
  var query = this.Query<DocumentIndex.Projection, DocumentIndex>().Where(x=>x.Bar.In(baz));
  var query2 = query.ProjectFromIndexFieldsInto<Document>();
            var items = query2.Skip(offset).Take(pageSize).ToList();

           
foreach (var item in items)
           
{
                this.Session.Store(item); // Do nothing
                item
.Id = this.Session.Advanced.GetDocumentId(item);  // set Id to null           
           
}




You suggested to call Store() on the entities. It did nothing on the Id property.

I also tried the GetDocumentId() but it returns null.

Oren Eini (Ayende Rahien)

unread,
Dec 18, 2017, 8:46:22 AM12/18/17
to ravendb
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.

Pierre-Yves

unread,
Dec 18, 2017, 10:43:17 AM12/18/17
to RavenDB - 2nd generation document database
Yes, you are right !

However it looks strange to me...
For a field that is not stored, the index projection will retrieve the tokenized value. That is by design.
Then, if I project into the document's class, RavenDb loads the full document and the id should be the original one. But it is not. Why ?

Oren Eini (Ayende Rahien)

unread,
Dec 18, 2017, 3:55:08 PM12/18/17
to ravendb
Because for Id specifically, if we aren't finding the value, we'll check the __document_id stored value, which is stored in lower case.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages