简体   繁体   中英

How to update a Cosmos DB item from a Node JS app

I have a Cosmos Document DB with many items in it and I'd like to update a single item.

I've tried doing it like this:

const { resources: updatedItem } = await container.item(existingType).replace(newItem)

But get this error:

Illegal characters ['/', '\', '?', '#'] cannot be used in resourceId

Upon further research it's because the _rid is being read from the existingType and contains patterns like AAAAA==/

What is the best practice for dealing with this?

According to the API document

Read the item's definition. Any provided type, T, is not necessarily enforced by the SDK. You may get more or less properties and it's up to your logic to enforce it. If the type, T, is a class, it won't pass typeof comparisons, because it won't have a match prototype. It's recommended to only use interfaces.

There is no set schema for JSON items. They may contain any number of custom properties.

You can create entity class so that you can remove system properties.

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