0

This is most likely a rookie mistake but any help would be appreciated.... I am trying to update a document in cosmosDB from my node app (using PUG). But when I invoke the replace method...

async updateItem(item) {
  const itemId = item.ticketId;
  const {resource: replaced } = await this.tickets.item(itemId,itemId).replace(item);
  return replaced;
}

I get the following error:

RangeError [ERR_HTTP_INVALID_STATUS_CODE]: Invalid status code: TypeError: 
 C:\Users\donko\OneDrive\vscode\appstart\views\editticket.pug:30
   28|       .form-group
   29|         label.ticket-label(for='fk_ticket_status') Ticket Status : 
 >    30|         select(name="fk_ticket_status" value=ticket.fk_ticket_status required 

So my question is why is the call to the CosmosDb replace method failing on the page? I haven't gotten to the point where my code should be re-rendering the page? the item object is called via my router as:

  async updateTicket(req, res) {
   await this.ticketModel.updateItem(req.body);

By comparison, my addItem function works just fine:

async addItem(item) {
  debug('Adding a ticket to the database')
  item.submitted_date = Date.now();
  item.fk_ticket_status = 1;
  item.assigned_to = '';
  item.parent = '';
  const { resource: doc } = await this.tickets.items.create(item)
  return doc
}
1
  • can you paste the whole error Commented Feb 8, 2022 at 6:55

1 Answer 1

1

I figured out the problem. According to Partial document update in Azure Cosmos DB, to update a document using replace, the client needs to read it, update it locally and then send it over the wire as a whole document Replace API call. When I tried this, it worked fine:

const oldDoc = await this.getItem(itemId);
const newDoc = oldDoc;
newDoc.updated_date = Date.now();
//... more updates here
const {resource: replaced } = await this.tickets.item(itemId, itemId).replace(newDoc);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.