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

问题描述 投票:0回答:1

我尝试按属性以_find端点来查询沙发数据库服务器,以'$'(在本例中为$ 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"}
            }
        }
    }   
}

按预期工作。

似乎芒果服务器无法识别$ ref之类的属性。

我尝试使用“ \ $ ref”来转义属性,但没有成功。 (不是真的 !!!,请参阅更新)

是否有任何变通办法来查询诸如$ ref之类的属性?

couchdb couchdb-mango
1个回答
0
投票

注:OP提供了此答案作为对问题的更新。我已将其移至此处以符合站点标准。


该查询有效。
{
   "selector": {
      "contents": {
         "eClass": "auth#//User",
         "roles": {
            "$elemMatch": {
               "eClass": {
                  "$regex": ".*auth#//Role"
               },
               "\\$ref": {
                  "$regex": ".*59bb208006149f50bb32f76f4900c962.*"
               }
            }
         }
      }
   }
}

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

© www.soinside.com 2019 - 2024. All rights reserved.