Python 如何更改单个文档值的架构类型
我想将特定用户的默认类型从dict更改为stringPython 如何更改单个文档值的架构类型,python,flask,eve,Python,Flask,Eve,我想将特定用户的默认类型从dict更改为string DOMAIN = { 'item': { 'schema': { 'profile':{ 'type': 'dict' }, 'username': { 'type': 'string' }
DOMAIN = {
'item': {
'schema': {
'profile':{
'type': 'dict'
},
'username': {
'type': 'string'
}
}
}
}
假设我从x收到一个请求,那么用户类型不应该改变。如果我从y收到请求,用户类型应该从dict更改为string。如何在不影响其他人的情况下更改特定项目资源
TIA.您最好的方法可能是设置两个不同的API端点,一个用于X类型的用户,另一个用于Y类型的用户。两个端点将使用相同的底层数据源(更新相同的DB集合)。您可以通过为端点设置
数据源
来实现这一点,如下所示:
itemx = {
'url': 'endpoint_1',
'datasource': {
'source': 'people', # actual DB collection consumed by the endpoint
'filter': {'usertype': 'x'} # optional
'projection': {'username': 1} # optional
},
'schema': {...} # here you set username to dict, or string
}
冲洗并重复第二个端点。有关更多信息,请参阅。感谢您的快速响应,是否有可能覆盖特定资源的数据架构验证?