【问题标题】:Insert a nested document into a DocumentDB doc using Node.js使用 Node.js 将嵌套文档插入到 DocumentDB 文档中
【发布时间】:2018-05-15 12:48:44
【问题描述】:

将嵌套文档插入以下内容的最佳方法是什么?

{
    "id": "3af62b94-2031-4b85-9fd3-e13e7217d382",
    "Email": "test@ingeniuus.com",
    "Name": "test",
    "OrgRoles": null,
    "UpdatedDate": "2017-11-10T10:49:11.1962998Z",
    "CreatedDate": "2017-11-10T10:49:05.6247018Z",
    "IsDeleted": true,
    "_rid": "KFokAOUDHwEtAAAAAAAAAA==",
    "_self": "dbs/KFokAA==/colls/KFokAOUDHwE=/docs/KFokAOUDHwEtAAAAAAAAAA==/",
    "_etag": "\"00001e00-0000-0000-0000-5a0584270000\"",
    "_attachments": "attachments/",
    "_ts": 1510310951
}

理想情况下,我想在 OrgRoles 之后追加,以便文档看起来像:

{
    "id": "3af62b94-2031-4b85-9fd3-e13e7217d382",
    "Email": "test@ingeniuus.com",
    "Name": "test",
    "OrgRoles": null,
    "Devices": [
             "ID": "765476547",
             "name": "myDevice"
     ],
    "UpdatedDate": "2017-11-10T10:49:11.1962998Z",
    "CreatedDate": "2017-11-10T10:49:05.6247018Z",
    "IsDeleted": true,
    "_rid": "KFokAOUDHwEtAAAAAAAAAA==",
    "_self": "dbs/KFokAA==/colls/KFokAOUDHwE=/docs/KFokAOUDHwEtAAAAAAAAAA==/",
    "_etag": "\"00001e00-0000-0000-0000-5a0584270000\"",
    "_attachments": "attachments/",
    "_ts": 1510310951
}

我目前正在使用 Node.js DocumentDB 客户端进行搜索,因此想继续使用它,但似乎看不到推送或更新或等效方法

【问题讨论】:

    标签: javascript node.js azure-cosmosdb document-database


    【解决方案1】:

    您必须致电readDocument,在本地进行更新,然后使用replaceDocument 进行更新。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-29
      • 2012-04-14
      • 2019-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-25
      相关资源
      最近更新 更多