Domanda

I have the following code

        IDocumentSession documentSession = store.OpenSession();
        var schools = documentSession.Query<School>().Where(x => x.SchoolName == "My Primary School").ToList();
        foreach (var school in schools)
        {
            Console.WriteLine(school);
        }

        schools = documentSession.Query<School>().Where(x => x.Id == "109940").ToList();
        foreach (var school in schools)
        {
            Console.WriteLine(school.SchoolName);  // returns My Primary School
        }

When the first query runs, no records are returned, although I have a matching record in the database. however the second query returns a the record I am expecting. I am running the db as embedded and I havent set up any indexes myself

Update: so if I customise the query to wait for non stale results it works fine, do I need to create a permanent index?

È stato utile?

Soluzione

This is how RavenDB behaves. If there is no index to satisfy your query, RavenDB will create an index dynamically upon the query, and return with a stale results.

This is why the second time you get the result as you expected. This is one of the key designs of RavenDB, let the indexes do the work on the background and allow stale results rather blocking the query until the index is not stale.

In production the temp index will be promoted to auto index, once RavenDB will detect that the index has a regular use. Instead of relaying on auto indexes, you can also create a static index at some point.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top