通过数据存储中的 ID 或键查询

Query by ids or keys in datastore

使用 python,我有一个像这样的 google 数据存储 ndb 模型。

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)   

当我创建实体时,我为每个实体使用了自己的 ID (sting),因此我可以像这样进行查询(使用 remote_api):

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

结果是:

[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')]

如何查询 ID(或键)以获得低于(或高于)特定 ID(或键)的值

例如:

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

你可以这样做:

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