You could create an Index Product_ByThirPartyProductId and query it waiting for NonStale results in this case. Or you keep a constraint doc to do this check so you can use Raven.Load<ConstraintDoc>(arrayOfProductIds) then loop the returinng objetcts, if it`s null the corresponding Id doc doesn`t exist.
public class ConstraintDoc {
public string Id { get; set; } // this is the third party Id
public string ProductId { get; set; }
}
var arrayOfThirdPartyIds = [ 11111,22222,33333];
var existingDocs = Raven.Load<ConstraintDoc>(arrayOfTHisPartyIds.Select(x => "thirdpartydocs/" + x));
for(var i=0;i<arrayOfTHisPartyIds.Count;i++) {
if ( existingDocs[i] == null ) {
// constraint doc doesnt exist, create a new one!
} else {
// update the doc!
}
}
I`ve set up a nice system to run long running tasks while giving feedback to the user, i`ll try to put it on git later and post here since it might help you.