Hi i have a sample stored procedure created like this
Bulk insert
function bulkImport(items) {
var container = getContext().getCollection();
var containerLink = container.getSelfLink();
var items=[{
"UserAccountID":"1236",
"FirstName": "Sanjeev",
},{
"UserAccountID":"1235",
"FirstName": "Sanjeev",
}];
// The count of imported items, also used as current item index.
var count = 0;
// Validate input.
if (!items) throw new Error("The array is undefined or null.");
var itemsLength = items.length;
if (itemsLength == 0) {
getContext().getResponse().setBody(0);
}
// Call the create API to create an item.
tryCreate(items[count], callback);
function tryCreate(item, callback) {
var isAccepted = container.createDocument(containerLink, item, callback);
if (!isAccepted) getContext().getResponse().setBody(count);
}
function callback(err, item, options) {
if (err) throw err;
// One more item has been inserted, increment the count.
count++;
if (count >= itemsLength) {
// If we created all items, we are done. Just set the response.
getContext().getResponse().setBody(count);
} else {
// Create next document.
tryCreate(items[count], callback);
}
}
}
How to execute this sp in the cosmos emulator. How to set the partition key uniquely for each of the item.
Since the partition key should be unique we cannot provide a single partition key while executing.