Converting a document field's structure

33 views
Skip to first unread message

billba...@gmail.com

unread,
Aug 21, 2014, 10:22:51 AM8/21/14
to rav...@googlegroups.com
I have a situation where I need convert an existing document property (bool?) to another complex type (object with properties name and value). The property will have the same name but the structure needs to be changed to the new type. The related code entity's type has already been changed to the new complex type. A successful approach in accessing the original document value and evaluation can be done using a combination of ScriptedPatchRequest along with multiple PatchRequests to create and rename a temporary field and remove the old one works. It's just pretty clunky. It would be an advantage to get access directly to original field value and perform the evaluation prior to building up the new element and just modify the original field. Attempting to use LuceneQuery<dynamic> to return a dynamic type for evaluation in order to access the original document fails if the original Raven document value is set to true or false. A null, of course, is fine. Is there a more concise way to achieve the conversion?

Chris Marisic

unread,
Aug 21, 2014, 11:03:32 AM8/21/14
to rav...@googlegroups.com
Just don't do this. Use a new property. The name really is not THAT IMPORTANT to play all kinds of database wizardary.

If you must do this, you already acknowledged the best approach, create the new field and hydrate it across the database. (This is where you should just stop) But if you must, then delete the previous field, then rename the new field. Lots of work, no value gained.

Kijana Woodard

unread,
Aug 21, 2014, 11:05:09 AM8/21/14
to rav...@googlegroups.com
I was typing out another solution and ended up at Chris' answer.


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

Oren Eini (Ayende Rahien)

unread,
Aug 21, 2014, 11:05:41 AM8/21/14
to ravendb
You can do that by creating a document convertion listener, that will give you the raw data before the serialization, and allow you to modify it.



Oren Eini

CEO


Mobile: + 972-52-548-6969

Office:  + 972-4-622-7811

Fax:      + 972-153-4622-7811





On Thu, Aug 21, 2014 at 5:22 PM, <billba...@gmail.com> wrote:
I have a situation where I need convert an existing document property (bool?) to another complex type (object with properties name and value). The property will have the same name but the structure needs to be changed to the new type. The related code entity's type has already been changed to the new complex type. A successful approach in accessing the original document value and evaluation can be done using a combination of ScriptedPatchRequest along with multiple PatchRequests to create and rename a temporary field and remove the old one works. It's just pretty clunky. It would be an advantage to get access directly to original field value and perform the evaluation prior to building up the new element and just modify the original field. Attempting to use LuceneQuery<dynamic> to return a dynamic type for evaluation in order to access the original document fails if the original Raven document value is set to true or false. A null, of course, is fine. Is there a more concise way to achieve the conversion?

--

Chris Marisic

unread,
Aug 21, 2014, 11:09:07 AM8/21/14
to rav...@googlegroups.com
FWIW document conversion listeners are basically worthless. I have never once in my career found a point where I can have half hydrated data. You can't query it according to the new specifications. So this means if you use a document conversion listener you need to load & save every single relevant document. At this point it's silly to even create the conversion listener and just load and modify each document yourself.
Reply all
Reply to author
Forward
0 new messages