1

我正在现有的 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(不嵌入)......

我在这里想念什么?

4

1 回答 1

0

当前不支持嵌入子字段(字典)。从Document Embedding中的限制段落:

目前,我们支持通过位于任何子文档(嵌套字典和列表)中的引用嵌入文档。例如,查询 /invoices?/embedded={"user.friends":1} 将返回一个嵌入了用户及其所有朋友的文档,但前提是用户是子文档并且朋友是参考列表(可以是字典列表、嵌套字典等)。我们不支持多层嵌入。

于 2015-01-03T09:43:19.397 回答