This series of posts is going to cover some things I’ve learned using RavenDB, a document database solution for .NET.
I was working on a class (a User class) where I needed to add a property to the class that didn’t exist in the original version of the application. So, I went and added it to the C# class (User) and I also updated an Index in RavenDB to use this new property so that I could filter by it in a query. It built and when I deployed I could see that Raven was updating the index and did so in a timely manner.
I then went and wrote some code to filter by that new property in a query. The property I had added was a boolean type and so all of the models that I had in the database (some 50,000+ User documents) would just get the default value of false for this new property. However, when I went to run this query, no documents were returned. What happened was that when you add a new property to a model, it isn’t going to go and update all of your existing documents with a property value even if a default is implied or provided (as is the case with a bool being false by default). There is simply no property in the JSON store in the User document that matches this property I was querying by.
The solution is that when you do something like that, you need to run a Patch in RavenDB. This will ensure that all of your documents get synced to the new additional property you have made. Perhaps if this was some integer or string property that had to be set to something specific I would have picked up on the problem before even attempting the query.