具有新字段/属性的投影查询将忽略尚未设置这些属性的条目

I have an Article type structured like this:

type Article struct {
    Title    string
    Content  string `datastore:",noindex"`
}

In an administrative portion of my site, I list all of my Articles. The only property I need in order to display this list is Title; grabbing the content of the article seems wasteful. So I use a projection query:

q := datastore.NewQuery("Article").Project("Title")

Everything works as expected so far. Now I decide I'd like to add two fields to Article so that some articles can be unlisted in the public article list and/or unviewable when access is attempted. Understanding the datastore to be schema-less, I think this might be very simple. I add the two new fields to Article:

type Article struct {
    Title    string
    Content  string `datastore:",noindex"`

    Unlisted   bool
    Unviewable bool
}

I also add them to the projection query, since I want to indicate in the administrative article list when an article is publicly unlisted and/or unviewable:

q := datastore.NewQuery("Article").Project("Title", "Unlisted", "Unviewable")

Unfortunately, this only returns entries that have explicitly included Unlisted and Unviewable when Put into the datastore.

My workaround for now is to simply stop using a projection query:

q := datastore.NewQuery("Article")

All entries are returned, and the entries that never set Unlisted or Unviewable have them set to their zero value as expected. The downside is that the article content is being passed around needlessly.

In this case, that compromise isn't terrible, but I expect similar situations to arise in the future, and it could be a big deal not being able to use projection queries. Projections queries and adding new properties to datastore entries seem like they're not fitting together well. I want to make sure I'm not misunderstanding something or missing the correct way to do things.

  1. It's not clear to me from the documentation that projection queries should behave this way (ignoring entries that don't have the projected properties rather than including them with zero values). Is this the intended behavior?

  2. Are the only options in scenarios like this (adding new fields to structs / properties to entries) to either forgo projection queries or run some kind of "schema migration", Getting all entries and then Puting them back, so they now have zero-valued properties and can be projected?

Projection queries source the data for fields from the indexes not the entity, when you have added new properties pre-existing records do not appear in those indexes you are performing the project query on. They will need to be re-indexed.

You are asking for those specific properties and they don't exist hence the current behaviour.

You should probably think of a projection query as a request for entities with a value in a requested index in addition to any filter you place on a query.