RavenDB and creating indexes – newbie gotcha! (and other Raven thoughts)
I’ve been playing with a hobby project on RavenDB and FubuMVC. I’m 100% newbing it up to both technologies, but I like a lot of what I see in both.
Anywhos, almost all the “getting started” RavenDB tutorials recommend putting a line of code in your application startup (Global.asax for Asp.NET MVC) that will scan a given assembly for any indexes, and add them for you. Pretty awesome, right? Because you can’t query against an index if it isn’t there. Here’s the line:
IndexCreation.CreateIndexes(Assembly.GetCallingAssembly(), DocumentStoreInstance);
I had this, yet my new index did not get picked up! I changed the Assembly.GetCallingAssembly() line to be typeof(MyIndexType).Assembly to make sure I wasn’t grabbing the wrong assembly. My query on the index still blows up with “index not found”. I open the RavenDB web UI, and the index isn’t there. I look on the file system, and I can even *see* the index in the folder!
To cut a long story short (4 hours worth, boy do I feel dumb), I was trying to be A Good Developer, and I was using tenants in RavenDB. Tenants are like creating a database in SQL Server. See, you can use RavenDB without creating a tenant. It just dumps everything in System. That’d be like creating your tables in the “master” database in SQL Server. The line above, of course, does not specify a tenant. The solution?
var catalog = new CompositionContainer(new AssemblyCatalog(typeof(MyIndexType).Assembly)); IndexCreation.CreateIndexes(catalog, DocumentStoreInstance.DatabaseCommands.ForDatabase("YourTenantName"), DocumentStoreInstance.Conventions);
I’d like to see an overload for IndexCreation that makes that a little simpler and easier to consume, but not the end of the world. Hopefully that helps someone else getting started to RavenDB!
Other Raven thoughts
Because I can’t stop talking…I’m not sure why RavenDB uses the words “tenants”. Even the web UI calls them Databases, and the method above says “ForDatabase”. Yet you’ll see some talk about multi-tenancy in relation to RavenDB. The 10 tips and tricks page on RavenDB’s site calls them tenants. I’m not sure if I’m using the wrong term, or if it’s a case of there not being a preferred term, and it all means the same thing.
I also don’t like what I call “the broken intro”. Remember when you were new to the world of software, and you wrote your first hello world website? And how that tutorial had you happily concatenate SQL right from a textbox and push that down to your database? I call that a broken intro – when the introduction to something is The Wrong Way to do it. I’ll probably make a bigger post on this some day, but the point is most of the intro stuff on RavenDB’s site has you dumping stuff into the “system” database. That’s even a protected database on the web UI, and it bitches at you for going there.
My last thought is how much I love working with RavenDB so far :3. A native .NET API, no fighting persistence related nightmares, and a great administrative interface. I know it’s just the honeymoon stage, but I really enjoy it.
9:34 PM | Labels: Coding, RavenDB | 1 Comments