tags:

views:

162

answers:

1

I'm reading through Rob Ashton's excellent blog post on RavenDB: http://codeofrob.com/archive/2010/05/09/ravendb-an-introduction.aspx

and I'm working through the code as I read. But when I try to add an index, I get a 401 error. Here's the code:

class Program
{
    static void Main(string[] args)
    {
        using (var documentStore = new DocumentStore() { Url = "http://localhost:8080" })
        {

            documentStore.Initialise();

            documentStore.DatabaseCommands.PutIndex(
                "BasicEntityBySomeData",
                new IndexDefinition<BasicEntity, BasicEntity>()
                {
                    Map = docs => from doc in docs
                                  where doc.SomeData != null
                                  select new
                                  {
                                      SomeData = doc.SomeData
                                  },
                });


            string entityId;

            using (var documentSession = documentStore.OpenSession())
            {
                var entity = new BasicEntity()
                {
                    SomeData = "Hello, World!",
                    SomeOtherData = "This is just another property",
                };

                documentSession.Store(entity);
                documentSession.SaveChanges();

                entityId = entity.Id;

                var loadedEntity = documentSession.Load<BasicEntity>(entityId);
                Console.WriteLine(loadedEntity.SomeData);

                var docs = documentSession.Query<BasicEntity>("BasicEntityBySomeData")
                    .Where("SomeData:Hello~")
                    .WaitForNonStaleResults()
                    .ToArray();

                docs.ToList().ForEach(doc => Console.WriteLine(doc.SomeData));

                Console.Read();
            }

        }
    }

It throws the 401 error when on the line that makes the PutIndex() call. Any ideas what permissions I need to apply? And where I need to apply them?

+1  A: 

Hey =)

What do you mean by Server mode? Do you mean simply executing Raven.Server?

I've not had to do anything special client-side to get that to work, although I have had to run Raven.Server with elevated privileges because I'm not sure the code to ask for relevant permissions is quite working as intended. (Actually, I'll raise a query about that on the mailing list)

You shouldn't be getting a 401 error unless you've changed the configuration of Raven.Server.

If you're running the server, you can browse to it directly using the url specified in configuration (localhost:8080 by default) - make sure it's actually running and working as intended before continuing with troubleshooting

Rob Ashton
I feel I should add a disclaimer here, that although I've been writing blog entries on the subject, I am *not* an expert in how RavenDB should operate, or function - and only know what I've found out in my use of it so far - which is probably more than most people because I've used it more than most people so far, but less than say, the guy who wrote it (Oren)
Rob Ashton
Hi Rob, thanks for the answer, and for the really detailed blog post - good stuff! I have a grand total of 1 hr of experience with RavenDB, so you're more of an expert than me.For the moment, I got myself up and running by setting the Raven/AnonymousAccess key to "All". I'm sure that's not the long-term solution, but it's enough to get me over this hump so I can do some experimenting.
dalesmithtx
That should be the default setting in Raven.Server - apologies for not mentioning it explicitly
Rob Ashton
This caught me out too - the odd thing was my app could anonymously add a few documents before getting the 401 error, which confused me a bit.
GraemeF