Swizec Teller
Swizec Teller

Reputation: 2322

GQL query for <missing>

When you change data models on the app engine to add new properties those entries without a certain property are listed with the value <missing> in the online data viewer.

What I'm wondering is how can I write a query to find those entries?

Upvotes: 8

Views: 1090

Answers (3)

Shaun
Shaun

Reputation: 1601

Or you could create a script to stick null in there for all current items that don't have that property using the low level datastore API, so then you can query on null.

I had this issue and that's how I solved it. The rough code would look like:

DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
        Query query = new Query("JDOObjectType");
        List<Entity> results = datastore.prepare(query).asList(FetchOptions.Builder.withLimit(9999));

        for (Entity lObject : results) {
            Object lProperty = lObject.getProperty("YOUR_PROPERTY");
            if (lProperty == null) {
                lObject.setProperty("YOUR_PROPERTY", null);
                datastore.put(lProperty);
            }
        }

    }

Upvotes: 0

Constantin
Constantin

Reputation: 28164

There is no direct way to query for older entities with missing attribute, but you can design data model upfront to support this. Add a version attribute to each model class. Version should have a default value, which is increased every time model class is changed and deployed. This way you will be able to query entities by version number.

Upvotes: 8

Nick Johnson
Nick Johnson

Reputation: 101149

There's no way to query the datastore for entities that don't have a given property. You need to iterate over all the entities and check each one - possibly by using the mapreduce API.

Upvotes: 4

Related Questions