0

I'd like to retrieve

  • document with _id of 1

    OR

  • document with value === 13 AND anotherValue === 56

Error:

There is no index available for this selector.

This is my query:

{
  "selector": {
      "$or": [
          {
              "_id": "1"
          },
          {
              "value": "13",
              "anotherValue": "56"
          }
       ]
   }
}

Indexes setup:

Your available Indexes:
special: _id
json: value, anotherValue
json: _id, value, anotherValue
Aurélien Bénel
  • 3,775
  • 24
  • 45
bobbyrne01
  • 6,295
  • 19
  • 80
  • 150

1 Answers1

3

For this query you need to add a selector to get all the IDs like so:

{
    "selector": {
        "_id": {"$gt":null},
        "$or": [
            {
                "_id": "1"
            },
            {
                "value": "13",
                "anotherValue": "56"
            }
        ]
    }
}

You can learn more here:

https://cloudant.com/blog/mango-json-vs-text-indexes/

And this SO post:

index and query items in an array with mango query for cloudant and couchdb 2.0

Alternatively, you can add a text index on all fields:

{
    "index": {},
    "type": "text"
}

And then your original selector should work.

Community
  • 1
  • 1
markwatsonatx
  • 3,391
  • 2
  • 21
  • 19
  • thanks! Any chance you could have a look at this one (similiar, but using `sort`): http://stackoverflow.com/questions/36868228/perform-sort-on-field-thats-not-primary-index – bobbyrne01 Apr 26 '16 at 15:05