GQL query for <missing>
Asked Answered
G

3

8

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?

Gonroff answered 6/9, 2010 at 15:23 Comment(0)
M
8

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.

Mak answered 8/9, 2010 at 12:14 Comment(1)
Hmm ... now if only I had thought of this before. Would probably be a good idea to implement now :)Gonroff
C
4

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.

Claypan answered 6/9, 2010 at 15:48 Comment(0)
G
0

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);
            }
        }

    }
Gastronome answered 6/1, 2014 at 21:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.