我从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的伙伴,请帮帮我
答案 0 :(得分:4)
虽然在@metadata
部分中返回了元数据,但这并不是您发送的方式。这是因为您无法控制每个元数据值。例如,传入etag是没有意义的。
相反,对于您可以控制的元数据值,请在HTTP标头中发送它们。
$headers = @{"Raven-Entity-Name"="Entries"}
Invoke-RestMethod -Headers $headers ...