eve - python eve中的“动态”数据源?
问题描述
我怎样才能从传入的后有效负载中获得一种动态数据源?因此,所有传入的有效负载在 mongodb 中“创建”一个新集合,或者使用旧集合(如果可用)...
前任。有效载荷:{ “a1”:“999”,“d1”:“06.05.2020 04:29:16”,“d2”:“0”,“d3”:“0”,“id2”:“3777”}
settings.py 的一部分:
mdata = {
'schema': {
**'a1': {
'type': 'string'**
},
'd1': {
'type': 'string'
},
'd2': {
'type': 'string'
},
'd3': {
'type': 'string'
},
'id2': {
'type': 'string'
}
},
'datasource': {
**'source': "a1-value" #should be 'a1' value from the post payload**
},
"resource_methods": ["POST"],
}
DOMAIN = {
"accounts": accounts,
"user": user,
"mdata": madata,
}
解决方案
在 中eve
,集合名称是您的资源名称:
例如,假设这是您的DOMAIN
:
DOMAIN = {
'test': <your_test_endpoint_variable>,
}
test
因此,当您请求此端点时,将创建一个具有名称的集合。
但是source
是
资源使用的数据库集合的名称。如果省略,则假定资源名称也是有效的集合名称。
我建议阅读文档的这一部分:
https://docs.python-eve.org/en/stable/config.html#advanced-datasource-patterns
推荐阅读
- excel - 相当于 Excel 中的 NOT In 或 IN,就像 SQL 中一样,我不想使用 vlookup 或 match
- python - 过滤点云
- apache - 使用 .htaccess RewriteRule 捕获请求并将它们重写到同一服务器中的另一个域
- python - Linux 中的 Shell 脚本:bash --rcfile 选项后的命令问题
- java - Spring @Transactional 防止 @Service 中的 @Autowired
- python - 广发银行。具有可变数量参数的用户定义命令
- python - BAC0 python: BAC0.device APDU 超时
- mysql - 在存在 where 子句的情况下在更新中使用 case 语句会降低效率吗?
- c++ - Docker 没有运行 .exe 文件
- ssh - 开放 ssh 私钥的确切格式