【问题标题】:How to define as subresource list elements of embedded dictionaires in python eve如何在python eve中定义为嵌入式字典的子资源列表元素
【发布时间】:2016-10-25 13:23:44
【问题描述】:

我用这个架构定义了一个资源

# 'people' schema definition
'schema'= {
    'firstname': {
        'type': 'string',
        'minlength': 1,
        'maxlength': 10,
    },
    'lastname': {
        'type': 'string',
        'minlength': 1,
        'maxlength': 15,
        'required': True,
        'unique': True,
    },
    # 'role' is a list, and can only contain values from 'allowed'.
    'role': {
        'type': 'list',
        'allowed': ["author", "contributor", "copy"],
    },
    # An embedded list of 'strongly-typed' dictionary.
    'locations': {
        'type': 'list',
        'schema' {
            'type': 'dict',
            'schema': {
                'address': {'type': 'string'},
                'city': {'type': 'string'}
            },
        },
    },
    'born': {
        'type': 'datetime',
    },
}

是否可以通过引用相同的人员数据源将位置定义为子资源并对其进行搜索?

例如人//位置/

回复:地点列表

我需要将位置存储在人员文档中的原因是为了利用 mongo 中的文档原子性。

我可能需要在一个事务中更新一个人的多个位置。因此,我想确保一个人的所有需要​​的位置(或没有)都已更新。不可能有中间状态。

【问题讨论】:

    标签: eve


    【解决方案1】:

    不幸的是,这是不可能的(除其他外,正则表达式中的点符号)。但是,没有什么可以阻止您(或您的客户端应用程序)像这样查询 people 端点:

    people?where={"firstname": "<firstname>", "locations.city": "<city>"}
    

    这在性能方面也是理想的。写入仍然是原子的,一旦正确构建索引,查询就会得到优化。

    【讨论】:

      猜你喜欢
      • 2016-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-10
      • 2021-06-26
      相关资源
      最近更新 更多