尝试在RavenDb中修补文档
$a = array('Patches' => array('pref_roles' => "1,2,3"),
'Key' => "Users/".$user_id,
'Method' => 'Patch'
);
{"补丁" {" pref_roles":" 1,2,3"}"键":"用户/ 4""方法":"膜片"}
$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);
补丁永远不会通过。我哪里错了?
编辑。
在'脚本'
中添加$a = array('Patch' => array('Script' => 'this.natio = '.$natio.''),
'Key' => 'Users/'.$user_id,
'Method' => 'Patch');
我发帖
CURLOPT_CUSTOMREQUEST => 'POST',
到这个网址:
CURLOPT_URL => 'http://localhost:8080/databases/om/bulk_docs'
出现以下错误消息:
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()
)
玩了一下,看看我是否能找到合适的解决方案,但这并没有真正解决。
答案 0 :(得分:0)
以这种方式修补命令数据要求您传递实际操作。 看到: http://ravendb.net/docs/article-page/2.5/csharp/http-api/http-api-single
我建议您使用EVAL来使用Scripted补丁。
$a = array('Patch' => ('Script' => "this.pref_roles = [1,2,3["),
'Key' => "Users/".$user_id,
'Method' => 'Patch'
);