简体   繁体   中英

Insert a nested document into a DocumentDB doc using Node.js

what's the best way to insert a nested document into the following?

{
    "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
}

Ideally I want to append after OrgRoles so that the doc would look like:

{
    "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
}

I'm currently using the Node.js DocumentDB client to do my searches so would like to continue to use this but can't seem to see a push or update or equivalent method in there

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM