RavenDB Query Documents with Property Removed

自作多情 提交于 2019-12-12 10:04:21

问题


In the RavenDB Studio, I can see 69 CustomVariableGroup documents. My query only returns 66 of them. After some digging, I see that the three docs that are not returned have the new class structure: a property was removed. Since I saved these three CustomVariableGroup documents, their structure is different from the other 66. Why though, when I query for all of them, do I only get the other 66 documents with the old structure?

Both my C# code, and my query in LinqPad, only return the 66. Here's the LinqPad query:

Session.Query<CustomVariableGroup>().Dump();  // returns 66 docs

But, if I do this, I can get one of the three documents that is missing from the above query:

Session.Query<CustomVariableGroup>().Where(x => x.Name == "Derating").Dump();

How can I get all 69 documents returned in one query?

** Edit: Index Info **

In the SQL tab of the LinqPad query (and in the Raven server output), the index looks like this:

Url: /indexes/dynamic/CustomVariableGroups?query=&start=0&pageSize=128&aggregation=None

I don't see that index in Raven Studio, presumably because it's dynamic.

** Edit 2: This HACK works **

If I do this, I get all 69 documents:

Session.Query<CustomVariableGroup>().Where(x => x.Name != string.Empty).Dump();

My guess is that Raven must be using an old index that only gets documents that still contain that deleted column. I somehow need to use a new/different index...

Interestingly, this does not work; it only returns 66:

Session.Query<CustomVariableGroup>().Where(x => x.Id != string.Empty).Dump();

** Edit 3: This HACK works as well **

Session.Advanced.LuceneQuery<CustomVariableGroup>("Raven/DocumentsByEntityName").Where("Tag:CustomVariableGroups").Dump();

回答1:


An index, with the old property, had to be removed.

** Before ** This didn't work (only returned 66 of the 69 documents):

Session.Query<CustomVariableGroup>().Dump();

** Fix ** Delete index that used the old property that was deleted from my C# class:

In Raven Studio, I deleted this index: Auto/CustomVariableGroups/ByApplicationId

** After ** This same query now returns all 69 documents:

Session.Query<CustomVariableGroup>().Dump();

Now, I'm not sure why these queries would use that index. I'm querying for all CustomVariableGroup documents, and not ByApplicationId. However, removing that index fixed it. I'm sure someone else can explain why.




回答2:


What do the indexes look like? Did you manually create the indexes or were they dynamically created? Just wondering if that is the cause of the issue based on your comments above that there was a structure change to the object.

--S




回答3:


Could it be a stale index.. if its not returning all the results you expect.

You could use

.Customize(x=>x.WaitForNonStaleResultsAsOfLastWrite())



来源:https://stackoverflow.com/questions/9446925/ravendb-query-documents-with-property-removed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!