Python-Eve。申报对象ID对Cerberus的模式阵列
问题描述:
我开发与Python,夏娃的API,我需要使用地狱犬来表达类似下面的文档创建MongoDB的模式声明:Python-Eve。申报对象ID对Cerberus的模式阵列
{
name : 'John Smith',
type: 'home',
devices : [
ObjectID('1234'),
ObjectID('ABCD'),
ObjectID('D2AF'),
],
}
我想要知道我如何声明一个Cerberus模式拥有ObjectID
的数组,以及上面的devices
键。
我想对其他文档,阵列架构,也许让他们嵌入,如低于单个元素架构例如,从Python的前夕documentation采取:
{
'author': {
'type': 'objectid',
'data_relation': {
'resource': 'users',
'field': '_id',
'embeddable': True
},
},
}
我怀疑这将需要一个自定义类型,但我仍然没有想到如何做到这一点。
答
OK,找到如何表达的设备:
{
'devices': {
'type': 'list',
'schema': {
'type': 'objectid',
'data_relation': {
'resource': 'devices',
'field': '_id',
'embeddable': True
},
}
}
}
优秀的Cerberus documentation有它。