fermaf
fermaf

Reputation: 13

Query by ids or keys in datastore

Using python, I have a google datastore ndb model like this.

class Persona(ndb.Model):
    name = ndb.StringProperty(repeated=True)  
    names= ndb.StringProperty(default="")
    address = ndb.StringProperty(indexed=False)
    city = ndb.StringProperty()
    count = ndb.IntegerProperty(default=0)   

When I created the entities I used my own ids (sting) for each entity, so I can do queries (using remote_api) like this:

data_person.Person.query(data_person.Person.name=="Adam").fetch(10,keys_only=True)

And the result is:

[Key('Person', '16.240.886'), Key('Person', '17.722.453'), Key('Person', '13.627.225'), Key('Person', '18.223.406'), Key('Person', '18.460.819'), Key('Persona', '17.047.133'), Key('Person', '12.875.781'), Key('Person', '13.182.078'), Key('Person', '14.186.000'), Key('Person', '14.424.659')]

How can I query Ids (or Keys) in order to get vales lower (or higher) than an specific Id (or Key)

For example:

query(Person.id()<'16.240.886')  #I know this is wrong, is just understand the idea order to get all the keys lower then the specific id

Upvotes: 0

Views: 2203

Answers (1)

Victor M. Alvarez
Victor M. Alvarez

Reputation: 396

You can do this:

Person.query().filter(Person.key < ndb.Key(Person, '16.240.886'))

Upvotes: 1

Related Questions