CouchDB 如何通过以$开头的属性查找

zbsbpyhn  于 8个月前  发布在  CouchDB
关注(0)|答案(1)|浏览(99)

我尝试使用_find endpoint by属性查询couchdb服务器,从'$'开始(在我的例子中是$ref)。但服务器总是返回空文档集。
1.我有这样的CouchDB文档:

{
  "_id": "59bb208006149f50bb32f76f4900ccfa",
  "_rev": "1-99022821cc2bb3ab0bdd84ab98b55828",
  "contents": {
    "eClass": "auth#//User",
    "name": "SuperAdminUser",
    "roles": [
      {
        "eClass": "auth#//Role",
        "$ref": "59bb208006149f50bb32f76f4900c962?rev=1-24d9469afe50f162e473b09fdbd95154#/"
      }
    ],
    "email": "[email protected]",
  }
}

1.我试着这样查询这个文档:

{
    "contents": {
        "eClass": "auth#//User",
        "roles": {
            "$elemMatch": {
                "eClass": {"$regex": ".*auth#//Role"},
                "$ref": {"$regex": "^59bb208006149f50bb32f76f4900c962.*"}
            }
        }
    }   
}

但没有返回结果。
1.查询类似

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

工作如预期。
mango服务器似乎无法识别$ref等属性。
我尝试用“$ref”转义属性,但没有成功。(不真实!!!,见更新)
是否有任何变通方法来查询像$ref这样的属性?

bvjveswy

bvjveswy1#

此查询有效。

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

所以只需要使用“\$ref”转义样式。

相关问题