Re: Programmatically update Raven/Hilo/collectionname document

599 views
Skip to first unread message

Chris Marisic

unread,
Feb 6, 2013, 10:13:18 AM2/6/13
to rav...@googlegroups.com
Load<dynamic>(hi-lo doc key)

On Wednesday, February 6, 2013 9:15:49 AM UTC-5, Christophe Gijbels wrote:
Hi,
 
Is there a way to programmatically adapt the Max value of a Raven/Hilo/collectionname document?
I know you can update the document by means of the RavenDb Studio, but when using RavenDb in embedded mode and without the possibility to run the studio (like in a hosting environment where you can only use port 80 for your website) that is not an option.
 
Scenario is where you create documents with an assigned id because you generate them based on data from a SQL database and would like to keep the original Ids. Once the import is done, the current Hilo document for the given collection should have an appropriate Max value based on the highest existing id.
If we don't adapt the max value, we get "PUT attempted on document 'collectionname/9999' using a non current etag" error, which is normal since the Hilo max value does not correspond to the actual stored documents.
 
I know there are other scenarios where you import all existing data with freshly generated id's while storing the original ids and then update all the "bad references" to the freshly created id's after which the old ones can be removed, but I would like to check if there is an easier solution, by just adapting the Hilo value.
 
Any idea how to adapt this value?
Or is it possible to run the studio on the same port as the application where it is embedded in (port 80 to be precise -> website) so that we can adapt the document directly?
 
Or should I keep on trying until it succeeds? Creating and deleting dummy documents until the Hilo value has reached to appropriate number?
 
Thanks for any feedback
 
Christophe

Chris Marisic

unread,
Feb 6, 2013, 10:13:56 AM2/6/13
to rav...@googlegroups.com
Also i think you can just do

session.Store(new { Id = ...., hi-lo properties all set })

Oren Eini (Ayende Rahien)

unread,
Feb 6, 2013, 11:51:31 AM2/6/13
to ravendb
It is a document, you can just update it like any other document


On Wed, Feb 6, 2013 at 4:15 PM, Christophe Gijbels <christoph...@gmail.com> wrote:
Hi,
 
Is there a way to programmatically adapt the Max value of a Raven/Hilo/collectionname document?
I know you can update the document by means of the RavenDb Studio, but when using RavenDb in embedded mode and without the possibility to run the studio (like in a hosting environment where you can only use port 80 for your website) that is not an option.
 
Scenario is where you create documents with an assigned id because you generate them based on data from a SQL database and would like to keep the original Ids. Once the import is done, the current Hilo document for the given collection should have an appropriate Max value based on the highest existing id.
If we don't adapt the max value, we get "PUT attempted on document 'collectionname/9999' using a non current etag" error, which is normal since the Hilo max value does not correspond to the actual stored documents.
 
I know there are other scenarios where you import all existing data with freshly generated id's while storing the original ids and then update all the "bad references" to the freshly created id's after which the old ones can be removed, but I would like to check if there is an easier solution, by just adapting the Hilo value.
 
Any idea how to adapt this value?
Or is it possible to run the studio on the same port as the application where it is embedded in (port 80 to be precise -> website) so that we can adapt the document directly?
 
Or should I keep on trying until it succeeds? Creating and deleting dummy documents until the Hilo value has reached to appropriate number?
 
Thanks for any feedback
 
Christophe

--
You received this message because you are subscribed to the Google Groups "ravendb" 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/groups/opt_out.
 
 

Chris Marisic

unread,
Feb 6, 2013, 11:58:15 AM2/6/13
to rav...@googlegroups.com
This is one of my favorite features of RavenDB. The system documents are just regular documents, and can be modified by the admin. Sure you can break everything if you make bad modifications to system docs, but I love that I'm trusted to know what I'm doing. Sql Server will fight you tooth and nail in just about everything if you want to make some kind of seemingly trivial but arcane change. (like messing with identity, good luck)

Christophe Gijbels

unread,
Feb 6, 2013, 6:42:08 PM2/6/13
to rav...@googlegroups.com
Hi
 
Thanks for the feedback. I tried a couple of things mentioned by Chris
 
When I tried the dynamic approach by calling
var hiloDocument = session.Query<dynamic>("Raven/Hilo/collectionname");
hiloDocument.Max = 1000;
 
Then I got a runtime error saying 'Raven.Abstractions.Linq.DynamicJsonObject' does not contain a definition for 'Max'
Maybe this approach only works when reading the data, not changing it?
 
Then I tried the other approach of just overwriting the existing document by storing a new document with the same id like
session.Store(new { Id = "Raven/Hilo/collectionname", Max = 1000 });
 
and there the new value was stored as expected, but for the change to take effect I had to recycle de website aka restart de RavenDb server?
Can it be related to the fact that the metadata of that document has changed? Because I see different values for Hilo related documents like
 
{
  "Raven-Entity-Name": "Raven"
}
 
or just
 
{
}
 
or I my case after overwriting the document by storing an anonymous type with the same Id
 
{
  "Raven-Clr-Type": "<>f__AnonymousType4`2[[System.String, mscorlib][System.Int32, mscorlib]], MyWebApp"
}
 
Do these different metadata data have an impact on how Hilo documents are treated internally? Or can I ignore this and just adapt all my Hilo documents and restart the server and all is good?
 
Anyway, thanks for the feedback, it solved my problem
 
Christophe

Oren Eini (Ayende Rahien)

unread,
Feb 7, 2013, 7:10:37 AM2/7/13
to ravendb
var hiloDocument = session.Query<dynamic>("Raven/Hilo/collectionname");

This returns an IQueryable on a missing index, it wouldn't work.

You probably want:

var hilo = session.Load<RavenJObject>("Raven/Hilo/users");
hilo["Max"] =  1000;
session.SaveChanges();

Note that you might need to create a new document store for it to catch up with the update.
Reply all
Reply to author
Forward
0 new messages