0

I try to query couchdb server with _find endpoint by attribute, starting with '$' ($ref in my case). But server always returns empty document set.

  1. I have couchdb documents like this:
{
  "_id": "59bb208006149f50bb32f76f4900ccfa",
  "_rev": "1-99022821cc2bb3ab0bdd84ab98b55828",
  "contents": {
    "eClass": "auth#//User",
    "name": "SuperAdminUser",
    "roles": [
      {
        "eClass": "auth#//Role",
        "$ref": "59bb208006149f50bb32f76f4900c962?rev=1-24d9469afe50f162e473b09fdbd95154#/"
      }
    ],
    "email": "admin@mydomain.ru",
  }
}
  1. I try to query this document like this:
{
    "contents": {
        "eClass": "auth#//User",
        "roles": {
            "$elemMatch": {
                "eClass": {"$regex": ".*auth#//Role"},
                "$ref": {"$regex": "^59bb208006149f50bb32f76f4900c962.*"}
            }
        }
    }   
}

but no results returned.

  1. Query like
{
    "contents": {
        "eClass": "auth#//User",
        "roles": {
            "$elemMatch": {
                "eClass": {"$regex": ".*auth#//Role"}
            }
        }
    }   
}

works as expected.

It seems the mango server did not recognize attributes like $ref.

I tried to escape attribute with "\$ref" with no success. (not true!!!, see update)

Is there any workarounds to query such attributes like $ref?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Oleg Orlov
  • 46
  • 3

1 Answers1

0

Note: OP provided this answer as an update to the question. I've moved it here to conform to site standards.


This query works.
{
   "selector": {
      "contents": {
         "eClass": "auth#//User",
         "roles": {
            "$elemMatch": {
               "eClass": {
                  "$regex": ".*auth#//Role"
               },
               "\\$ref": {
                  "$regex": ".*59bb208006149f50bb32f76f4900c962.*"
               }
            }
         }
      }
   }
}

So just use "\\$ref" escape style.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189