DocumentDB select document at specific index -
is possible select document @ specific index?
i have document import process, page of items data source (250 items @ once) import these documentdb in concurrently. assuming error inserting these items documentdb wont sure individual item or items failed. (i work out don't want to). easier upsert items page again.
the items i'm inserting have ascending id. if query documentdb (ordered id) , select id @ position (count of id's - page size) can start importing point forward again.
i know skip not implemented, want check if there option?
you try bulk import stored procedure. sproc creation code below azure's github repo. sproc report number of docs created in batch , continue trying create docs in multiple batches if sproc times out.
since sproc acid, have retry beginning (or last successful batch) if there exceptions thrown. change createdocument function upsertdocument if want retry entire batch process if exception thrown.
{ id: "bulkimportsproc", body: function bulkimport(docs) { var collection = getcontext().getcollection(); var collectionlink = collection.getselflink(); // count of imported docs, used current doc index. var count = 0; // validate input. if (!docs) throw new error("the array undefined or null."); var docslength = docs.length; if (docslength == 0) { getcontext().getresponse().setbody(0); return; } // call crud api create document. trycreate(docs[count], callback); // note there 2 exit conditions: // 1) createdocument request not accepted. // in case callback not called, call setbody , done. // 2) callback called docs.length times. // in case documents created , don't need call trycreate anymore. call setbody , done. function trycreate(doc, callback) { var isaccepted = collection.createdocument(collectionlink, doc, callback); // if request accepted, callback called. // otherwise report current count client, // call script again remaining set of docs. // condition happen when stored procedure has been running long // , cancelled server. allow calling client // resume batch point got before isaccepted set false if (!isaccepted) getcontext().getresponse().setbody(count); } // called when collection.createdocument done , document has been persisted. function callback(err, doc, options) { if (err) throw err; // 1 more document has been inserted, increment count. count++; if (count >= docslength) { // if have created documents, done. set response. getcontext().getresponse().setbody(count); } else { // create next document. trycreate(docs[count], callback); } } } }
Comments
Post a Comment