3

我正在从 PowerShell脚本将文档上传到 RavenDB 。这里是:

$Timestamp = (Get-Date).ToBinary()
$Url = "http://127.0.0.1:8080/databases/DiskStat/docs"

$diskObject = New-Object PSObject @{
    "@metadata" = New-Object psobject @{
        "Raven-Entity-Name" = "Entries"
    }
    Timestamp = $Timestamp
    Computer = $comp
    Disk = $disk.DeviceID
    Size = $disk.Size
    Free = $disk.FreeSpace
}
[string]$diskJson = (ConvertTo-Json $diskObject)
Invoke-RestMethod -Uri $Url -Method Put -Body $diskJson | Out-Null

问题是新文档不属于任何集合@metadata被忽略。文档在数据库中看起来像这样:

{
  "Size": 52427931648,
  "Timestamp": -8588258377456088029,
  "Computer": "710H0001",
  "Free": 27922563072,
  "Disk": "C:",
  "@metadata": {
    "@id": "423b5bdf-fe59-4530-8047-bc48d98ee363",
    "Last-Modified": "2013-08-06T06:05:42.6982277Z",
    "@etag": "00000001-0000-a900-0000-000000000001",
    "Non-Authoritative-Information": false
  }
}

所以我不得不时不时地给它打补丁来分配Raven-Entity-Name。酷 RavenDB 伙计们,请帮帮我

4

1 回答 1

4

虽然在该@metadata部分中返回元数据,但这不是您发送它的方式。那是因为您无法控制每个元数据值。例如,传入一个 etag 是没有意义的。

相反,对于您可以控制的元数据值,请在 HTTP 标头中发送它们。

$headers = @{"Raven-Entity-Name"="Entries"}
Invoke-RestMethod -Headers $headers  ...
于 2013-08-07T14:39:37.590 回答