Friday, 6 July 2018

Doofus Alert - Using Cloudant queries via cURL

I'm continuing to tinker with Cloudant, and am looking at how I can use indexes ( indices ? ) via the command-line using cURL.

This is what I'm sending: -

curl -X POST -H 'Content-type: application/json' -g $COUCH_URL/$COUCH_DATABASE/_find -d query.json

and this is what I'm seeing: -

{"error":"bad_request","reason":"invalid UTF-8 JSON"}

I checked my query: -

cat query.json 

{
   "selector": {
      "$or": [
         {
            "givenName": "Maggie"
         },
         {
            "givenName": "Lisa"
         }
      ]
   },
   "fields": [
      "givenName",
      "familyName"
   ],
   "sort": [
      {
         "givenName": "asc"
      }
   ]
}

and it looks OK.

Thankfully, this chap had already hit the same: -



Yep, that's exactly where I went wrong ….

I changed my query: -

curl -X POST -H 'Content-type: application/json' -g $COUCH_URL/$COUCH_DATABASE/_find -d @query.json

and … guess what ….

IT WORKED

{"docs":[
{"givenName":"Lisa","familyName":"Simpson"},
{"givenName":"Maggie","familyName":"Simpson"}
],
"bookmark": "g1AAAAA9eJzLYWBgYMpgSmHgKy5JLCrJTq2MT8lPzkzJBYozGoIkOGASOSAhkDibb2J6emZqVhYA5ooQDg"}

Can you say "Doofus" ? I bet you can ….

No comments: