Python 无法使用Eve获取dict内部的嵌入文档
我正在现有MongoDB结构的基础上构建一个只读API,似乎无法在我的主调用中显示嵌入式文档 有问题的样本文档(已编辑)Python 无法使用Eve获取dict内部的嵌入文档,python,eve,Python,Eve,我正在现有MongoDB结构的基础上构建一个只读API,似乎无法在我的主调用中显示嵌入式文档 有问题的样本文档(已编辑) { "_id": ObjectId("54a31721372a3b0f00000017"), "contentType": "document", "created": ISODate("2014-12-30T21:20:33.408Z"), "dcsId": "e14.0483", . . . , "metadata": { "amoun
{
"_id": ObjectId("54a31721372a3b0f00000017"),
"contentType": "document",
"created": ISODate("2014-12-30T21:20:33.408Z"),
"dcsId": "e14.0483",
. . .
,
"metadata": {
"amountTotal": 315.05,
"amountNeto": 252.04,
"partner": ObjectId("53bd4d851899424c0700005e")
},
. . .
docsSchema = {
'dcsId': {
'type': 'string',
'required': True,
'unique': True
},
'modified': {
'type': 'datetime'
},
'created': {
'type': 'datetime'
},
'downloadUrl': {
'type': 'string'
},
'metadata': {
'partner': {
'type': 'objectid',
'data_relation': {
'resource': 'partners',
'field': '_id',
'embeddable': True
}
},
'documentType': {'type': 'string'},
'amountTotal': {'type': 'float'},
'amountNeto': {"type": "float"}
}
}
from schemas import coreSchemas
ura = {
'datasource': {
'source': 'documents',
'filter': {'metadata.documentType': 'URA'},
'default_sort': [('_id', 2)],
'projection': {
"metadata.amountNeto": 1,
"metadata.amountTotal": 1,
"metadata.partner": 1,
"created": 1,
"modified": 1,
"dcsId": 1},
'embedding': True
},
'cache_control': 'max-age=10,must-revalidate',
'cache_expires': 10,
'resource_methods': ['GET'],
'scheme': coreSchemas.docsSchema,
'url': 'ura',
"embedded_fields": {"metadata.partner"}
}
partners = {
'datasource': {
'source': 'partners',
'filter': {'deleted': {'$ne': True}},
# 'projection': {'metadata': 1, 'modified':1,'created':1, 'drive.webContentLink' : 1 , 'deleted': {'$ne':True}}
},
'cache_control': 'max-age=10,must-revalidate',
'cache_expires': 10,
'resource_methods': ['GET'],
'scheme': coreSchemas.partnersSchema,
'url': 'partners',
"embedding": True
}
合作伙伴是我试图嵌入到文档调用中的内容
文档的我的架构(用作ura).
{
"_id": ObjectId("54a31721372a3b0f00000017"),
"contentType": "document",
"created": ISODate("2014-12-30T21:20:33.408Z"),
"dcsId": "e14.0483",
. . .
,
"metadata": {
"amountTotal": 315.05,
"amountNeto": 252.04,
"partner": ObjectId("53bd4d851899424c0700005e")
},
. . .
docsSchema = {
'dcsId': {
'type': 'string',
'required': True,
'unique': True
},
'modified': {
'type': 'datetime'
},
'created': {
'type': 'datetime'
},
'downloadUrl': {
'type': 'string'
},
'metadata': {
'partner': {
'type': 'objectid',
'data_relation': {
'resource': 'partners',
'field': '_id',
'embeddable': True
}
},
'documentType': {'type': 'string'},
'amountTotal': {'type': 'float'},
'amountNeto': {"type": "float"}
}
}
from schemas import coreSchemas
ura = {
'datasource': {
'source': 'documents',
'filter': {'metadata.documentType': 'URA'},
'default_sort': [('_id', 2)],
'projection': {
"metadata.amountNeto": 1,
"metadata.amountTotal": 1,
"metadata.partner": 1,
"created": 1,
"modified": 1,
"dcsId": 1},
'embedding': True
},
'cache_control': 'max-age=10,must-revalidate',
'cache_expires': 10,
'resource_methods': ['GET'],
'scheme': coreSchemas.docsSchema,
'url': 'ura',
"embedded_fields": {"metadata.partner"}
}
partners = {
'datasource': {
'source': 'partners',
'filter': {'deleted': {'$ne': True}},
# 'projection': {'metadata': 1, 'modified':1,'created':1, 'drive.webContentLink' : 1 , 'deleted': {'$ne':True}}
},
'cache_control': 'max-age=10,must-revalidate',
'cache_expires': 10,
'resource_methods': ['GET'],
'scheme': coreSchemas.partnersSchema,
'url': 'partners',
"embedding": True
}
我的合作伙伴模式
partnersSchema = {
"name": {"type": "string"}
}
和这两者的资源定义……
{
"_id": ObjectId("54a31721372a3b0f00000017"),
"contentType": "document",
"created": ISODate("2014-12-30T21:20:33.408Z"),
"dcsId": "e14.0483",
. . .
,
"metadata": {
"amountTotal": 315.05,
"amountNeto": 252.04,
"partner": ObjectId("53bd4d851899424c0700005e")
},
. . .
docsSchema = {
'dcsId': {
'type': 'string',
'required': True,
'unique': True
},
'modified': {
'type': 'datetime'
},
'created': {
'type': 'datetime'
},
'downloadUrl': {
'type': 'string'
},
'metadata': {
'partner': {
'type': 'objectid',
'data_relation': {
'resource': 'partners',
'field': '_id',
'embeddable': True
}
},
'documentType': {'type': 'string'},
'amountTotal': {'type': 'float'},
'amountNeto': {"type": "float"}
}
}
from schemas import coreSchemas
ura = {
'datasource': {
'source': 'documents',
'filter': {'metadata.documentType': 'URA'},
'default_sort': [('_id', 2)],
'projection': {
"metadata.amountNeto": 1,
"metadata.amountTotal": 1,
"metadata.partner": 1,
"created": 1,
"modified": 1,
"dcsId": 1},
'embedding': True
},
'cache_control': 'max-age=10,must-revalidate',
'cache_expires': 10,
'resource_methods': ['GET'],
'scheme': coreSchemas.docsSchema,
'url': 'ura',
"embedded_fields": {"metadata.partner"}
}
partners = {
'datasource': {
'source': 'partners',
'filter': {'deleted': {'$ne': True}},
# 'projection': {'metadata': 1, 'modified':1,'created':1, 'drive.webContentLink' : 1 , 'deleted': {'$ne':True}}
},
'cache_control': 'max-age=10,must-revalidate',
'cache_expires': 10,
'resource_methods': ['GET'],
'scheme': coreSchemas.partnersSchema,
'url': 'partners',
"embedding": True
}
我对“ura”端点的调用只给了我合作伙伴的id(不是嵌入)
我这里缺少什么?当前不支持嵌入子字段(DICT)。从中的限制段落:
目前,我们支持通过位于任何子文档(嵌套的dict和列表)中的引用嵌入文档。例如,查询/invoices?/embedded={“user.friends”:1}将返回一个包含用户及其所有好友的文档,但仅当用户是子文档且好友是一个引用列表时才返回该文档(它可以是一个dict、嵌套dict等的列表)。我们不支持多层嵌入
谢谢你的快速回答!非常希望在即将发布的版本中看到这种功能。。。。