I'm having difficulty with a partial document updating my JSON data model stored in Cosmos DB. Essentially what I'm trying to do is update the Individual Task nested JSON (example below) using the PatchOperation.Set (also tried PatchOperation.Replace) but keep getting the dreaded "Object Not Set To An Instance Of An Object" error. Right before calling this method, I do a query to get the indexes so that I can dynamically set the index for Individual Task Sets and Individual Task since it may reside in a different place. I'm using the filter predicate to get the right Individual Task since more then one can live under an Individual Task Set.
{
"GroupTask": [
{
"_type": null,
"GroupTaskID": "GUID",
"GroupTaskTitle": null,
"GroupTaskDescription": null,
"IndividualTaskSets": [
{
"SETID": "GUID",
"CreatedBy": "",
"CreatedDate": "0001-01-01T00:00:00",
"IndividualTask": [
{
"IndividualTaskID": "GUID",
"TaskStatus": "",
"TaskTitle": "",
"TaskType": "",
"TaskDescription": "",
"TaskNotes": "",
"Priority": "Normal",
"CreatedBy": "",
"CreatedDate": "0001-01-01T00:00:00"
}
]
}
]
}
],
"CaseID": "GUID",
"TenantID": "testtenant0004",
"id": "GUID",
"TaskID": "GUID"
}
Below is the code that I'm using and the filter predicate string that I'm sending is the following "FROM Task t JOIN g in t.GroupTask JOIN its IN g.IndividualTaskSets JOIN it IN its.IndividualTask WHERE it.IndividualTaskID ='" + itid + "'"
public async Task<string> UpdateIT(ReturnTaskObject rto, IndividualTask updatedIT, string path)
{
try
{
PatchItemRequestOptions patchItemRequestOptions = new PatchItemRequestOptions
{
FilterPredicate = path
};
ItemResponse<IndividualTask> response = await container.PatchItemAsync<IndividualTask>
(
id: rto.id,
partitionKey: new Microsoft.Azure.Cosmos.PartitionKey(rto.taskid),
patchOperations: new[] { PatchOperation.Set("/IndividualTaskSets/" + rto.individualtasksetidorindex + "/IndividualTask/" + rto.individualtaskidorindex + "/", updatedIT)},
//tried this approach without the filter predicate thinking that was the issue but also yields the same error
//patchOperations: new[] { PatchOperation.Replace("/GroupTask/0/IndividualTaskSets/" + rto.individualtasksetidorindex + "/IndividualTask/" + rto.individualtaskidorindex + "/", updatedIT) }
requestOptions: patchItemRequestOptions
);
string status = response.StatusCode.ToString();
return status;
}
catch (Exception e)
{
return e.Message;
}
}
Full Stack trace:
at CMaaS.Task.Service.DBUtil.UpdateIT(ReturnTaskObject rto,
IndividualTask updatedIT, String path)
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
at CMaaS.Task.Service.DBUtil.UpdateIT(ReturnTaskObject rto,
IndividualTask updatedIT, String path) at System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
at CMaaS.Task.Function.FunctionTaskController.RunUpdateIndividualTaskSetAsync(HttpRequest req, ILogger log)
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
at CMaaS.Task.Function.FunctionTaskController.RunUpdateIndividualTaskSetAsync(HttpRequest req, ILogger log)
at lambda_method149(Closure , FunctionTaskController , Object[] )
at Microsoft.Azure.WebJobs.Host.Executors.TaskMethodInvoker`2.InvokeAsync(TReflected instance, Object[] arguments)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`2.InvokeAsync(Object instance, Object[] arguments)
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.ExecutionContextCallback(Object s)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.MoveNext(Thread threadPoolThread)
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.MoveNext()
at System.Runtime.CompilerServices.YieldAwaitable.YieldAwaiter.<>c.<OutputCorrelationEtwEvent>b__6_0(Action innerContinuation, Task continuationIdTask)
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke()
at System.Runtime.CompilerServices.YieldAwaitable.YieldAwaiter.RunAction(Object state)
at System.Threading.QueueUserWorkItemCallbackDefaultContext.Execute()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()
at System.Threading.Thread.StartCallback()
}