如何按$开头的属性查找 [英] How to find by attribute starting with $

查看:119
本文介绍了如何按$开头的属性查找的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试按属性以_find端点查询沙发数据库服务器,以'$'(在我的情况下为$ ref)开头.但是服务器总是返回空文档集.

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. 我有如下这样的beddb文件:

{
  "_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. 我尝试这样查询此文档:

{
    "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之类的属性.

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

我试图用"\ $ ref"转义属性,但没有成功. (不是真的 !!!,请参阅更新)

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

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

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

推荐答案

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


该查询有效.

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.*"
               }
            }
         }
      }
   }
}

因此,只需使用"\\ $ ref"转义样式即可.

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

这篇关于如何按$开头的属性查找的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆