Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

180
Views
Create a nested object in CosmosDB (Js)

Building a react native app using CosmosDB and it's SQL api.

Per their documentation, I can add an object to a container like this:

const CosmosClient = require('@azure/cosmos').CosmosClient;

const client = new CosmosClient({ endpoint, key });

const myNewObject = {foo: "bar"}

 await client
.database(databaseId)
.container(containerId)
.items.create(myNewObject);

And I can confirm this works.

What I'm trying to do tho, is place data into that {foo: "bar"} document that already exists. So far I've tried chaining the .item method, but it does't work.

 await client
.database(databaseId)
.container(containerId)
.item(idOfMyNewObject) // The existing object I want to create a child in
.item('myNewChildObject') // new child of the parent
.create(newEntry); // new entry in the new child

Any ideas? the documentation doesn't seem to talk about this.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

There's no method on the container that does this for you. You must define the structure of the data yourself in your code. Here is an example of a customer record which has both an array of addresses as well as an embedded object.

const customer = {
"id": "000242A2-BF40-4220-864B-2770CAA38F5D",
"type": "customer",
"customerId": "000242A2-BF40-4220-864B-2770CAA38F5D",
"title": "",
"firstName": "Timothy",
"lastName": "Kelly",
"emailAddress": "timothy4@adventure-works.com",
"phoneNumber": "193-555-0189",
"creationDate": "2014-03-14T00:00:00",
"addresses": [
    {
        "addressLine1": "9918 Scottsdale Rd.",
        "addressLine2": "",
        "city": "Novato",
        "state": "CA ",
        "country": "US",
        "zipCode": "94947",
        "location": {
            "type": "Point",
            "coordinates": [
                -122.764,
                38.0852
            ]
        }
    }
],
"password": {
    "hash": "LvEbgjonEPU11HEeSXqdzTsmqNeUfuhxBNL82vGlCWA=",
    "salt": "61626BAE"
},
"salesOrderCount": 1
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!