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?

Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
dalesmithtx
  • 247
  • 1
  • 11

1 Answers1

1

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

metdos
  • 13,411
  • 17
  • 77
  • 120
  • 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) – metdos May 13 '10 at 20:26
  • 1
    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 May 13 '10 at 22:43
  • That should be the default setting in Raven.Server - apologies for not mentioning it explicitly – metdos May 13 '10 at 22:48
  • 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 Jun 10 '10 at 21:22