2016-04-02 20 views
0

Der Versuch, Dokumente in RavenDB PatchRavenDB HTTP Patchen

$a = array('Patches' => array('pref_roles' => "1,2,3"), 
       'Key' => "Users/".$user_id, 
       'Method' => 'Patch'     
); 

{ "Patches": { "pref_roles": "1,2,3"}, "Key": "Benutzer/4", "Method ":" Patch "}

$input = json_encode($input); 
$curl = curl_init(); 
curl_setopt_array($curl, array(
    CURLOPT_CUSTOMREQUEST => 'POST', 
    CURLOPT_RETURNTRANSFER => true, 
    CURLOPT_POSTFIELDS => $input, 
    CURLOPT_URL => 'http://localhost:8080/databases/om/bulk_docs' 
)); 
$resp = curl_exec($curl); 

Der Patch wird nie durchkommen. Wo gehe ich falsch?

Bearbeiten.

Added im 'script'

$a = array('Patch' => array('Script' => 'this.natio = '.$natio.''), 
      'Key' => 'Users/'.$user_id, 
      'Method' => 'Patch'); 

Ich

CURLOPT_CUSTOMREQUEST => 'POST', 

auf diese URL veröffentlichen:

CURLOPT_URL => 'http://localhost:8080/databases/om/bulk_docs' 

Mit diesen Fehlermeldungen:

Array 
(
    [Url] => /databases/om/bulk_docs 
    [Error] => System.Exception: Error reading RavenJArray from JsonReader. Current JsonReader item is not an array: StartObject 
    at Raven.Json.Linq.RavenJArray.Load(JsonReader reader) 
    at Raven.Database.Server.Controllers.RavenBaseApiController.<ReadJsonArrayAsync>d__11.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at Raven.Database.Server.Controllers.DocumentsBatchController.<BulkPost>d__8.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at System.Threading.Tasks.TaskHelpersExtensions.<CastToObject>d__3`1.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext() 
) 

Gespielt um ein wenig, um zu sehen, ob ich die funktionierende Lösung finden konnte, aber das hat nicht wirklich geklappt.

Antwort

0

Damit die Befehlsdaten auf diese Weise gepatcht werden können, müssen Sie die eigentlichen Operationen übergeben. Siehe: http://ravendb.net/docs/article-page/2.5/csharp/http-api/http-api-single

Ich schlage vor, dass Sie mit Scripted Patch gehen, mit EVAL.

$a = array('Patch' => ('Script' => "this.pref_roles = [1,2,3["), 
       'Key' => "Users/".$user_id, 
       'Method' => 'Patch'     
);