无法使用 Eve 获取 dict 中的嵌入式文档
Can not get embeddeded document inside of dict with Eve
我正在现有 MongoDB 结构之上构建只读 API,似乎无法在我的主调用中显示嵌入式文档。
有问题的示例文档(已编辑)..
{
"_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")
},
. . .
合作伙伴是我试图嵌入文档调用中的...
我的文档架构(用作 ura)...
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"}
}
}
我的伙伴架构
partnersSchema = {
"name": {"type": "string"}
}
以及两者的资源定义.....
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(不是嵌入)...
我在这里错过了什么?
当前不支持嵌入子字段(字典)。来自 限制 段落 Document Embedding:
Currently we support embedding of documents by references located in any subdocuments (nested dicts and lists). For example, a query /invoices?/embedded={"user.friends":1} will return a document with user and all his friends embedded, but only if user is a subdocument and friends is a list of reference (it could be a list of dicts, nested dict, ect.). We do not support multiple layers embeddings.
我正在现有 MongoDB 结构之上构建只读 API,似乎无法在我的主调用中显示嵌入式文档。
有问题的示例文档(已编辑)..
{
"_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")
},
. . .
合作伙伴是我试图嵌入文档调用中的...
我的文档架构(用作 ura)...
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"}
}
}
我的伙伴架构
partnersSchema = {
"name": {"type": "string"}
}
以及两者的资源定义.....
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(不是嵌入)...
我在这里错过了什么?
当前不支持嵌入子字段(字典)。来自 限制 段落 Document Embedding:
Currently we support embedding of documents by references located in any subdocuments (nested dicts and lists). For example, a query /invoices?/embedded={"user.friends":1} will return a document with user and all his friends embedded, but only if user is a subdocument and friends is a list of reference (it could be a list of dicts, nested dict, ect.). We do not support multiple layers embeddings.