Describe the bug
The container I have created is not following the unique key policy that I have set. I suspect this is due to the fact that both items are being persisted at the exact same time.
To Reproduce
Steps to reproduce the behavior:
- Insert two items that have the exact same _ts, subject and seq value.
- Both items persist in the database.
Expected behavior
I expect one or both of these documents to get rejected from persistence.
Screenshots


Additional context
Here is the code I used to create the container and set the unique key policy:
await db.containers.createIfNotExists({
id: eventstore,
partitionKey: { paths: ["/subject"] },
uniqueKeyPolicy: {
uniqueKeys: [
{ paths: ["/seq"] }
]
}
})
I am also using a stored procedure to insert items into this database:
function bulkInsertItems(items) {
var container = getContext().getCollection();
var containerLink = container.getSelfLink();
// Validate input
if (!items) throw new Error("The array is undefined or null.");
// End if there are no items
if (items.length == 0) {
getContext().getResponse().setBody(0);
}
items.map(item => {
var isAccepted = container.createDocument(containerLink, item);
// If the item fails to persist, throw an error and CosmosDB will handle rolling back
if (!isAccepted) {
throw new Error("Unable to create item");
}
})
getContext().getResponse().setBody(items.length);
}
Describe the bug
The container I have created is not following the unique key policy that I have set. I suspect this is due to the fact that both items are being persisted at the exact same time.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
I expect one or both of these documents to get rejected from persistence.
Screenshots


Additional context
Here is the code I used to create the container and set the unique key policy:
I am also using a stored procedure to insert items into this database: