Domanda

I'm uploading documents to RavenDB from PowerShell script. Here it is:

$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

The problem is that new documents do not belong to any collection, @metadata is ignored. Documents are looking like this in database:

{
  "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
  }
}

So I have to patch it from time to time to assign Raven-Entity-Name. Cool RavenDB guys, please, help me

È stato utile?

Soluzione

While metadata is returned in the @metadata section, that's not how you send it in. That's because you don't have control over every metadata value. For example, passing in an etag wouldn't make sense.

Instead, for the metadata values you can control, send them in the HTTP headers.

$headers = @{"Raven-Entity-Name"="Entries"}
Invoke-RestMethod -Headers $headers  ...
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top