javascript - 使用 Node.js 将嵌套文档插入 DocumentDB 文档

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

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

{
    "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 客户端进行搜索,因此想继续使用它,但似乎看不到其中的推送或更新或等效方法

最佳答案

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

关于javascript - 使用 Node.js 将嵌套文档插入 DocumentDB 文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47592964/

相关文章:

java - Cassandra - 用于选择和更新的分布式行锁定

javascript - Safari Inspector 时间线中的缺口,渲染时间长

node.js - JSON 中的 key 无法识别

javascript - 扩展 Javascript 中的方法

node.js - 独立的NPM库,根据swagger文件验证请求

javascript - 无法在 TypeScript 中导入 NPM 包(例如 Faker)

azure - 如何在 Azure cosmosDB 中执行事务批量操作

azure - 使用 dt.exe 命令行进行 Cosmosdb 迁移

javascript - "no-ops"在 Javascript 中是什么意思

javascript - 在 json 对象中添加额外的值