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

zbsbpyhn  于 2023-09-28  发布在  CouchDB
关注(0)|答案(1)|浏览(320)

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

  1. {
  2. "_id": "59bb208006149f50bb32f76f4900ccfa",
  3. "_rev": "1-99022821cc2bb3ab0bdd84ab98b55828",
  4. "contents": {
  5. "eClass": "auth#//User",
  6. "name": "SuperAdminUser",
  7. "roles": [
  8. {
  9. "eClass": "auth#//Role",
  10. "$ref": "59bb208006149f50bb32f76f4900c962?rev=1-24d9469afe50f162e473b09fdbd95154#/"
  11. }
  12. ],
  13. "email": "[email protected]",
  14. }
  15. }

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

  1. {
  2. "contents": {
  3. "eClass": "auth#//User",
  4. "roles": {
  5. "$elemMatch": {
  6. "eClass": {"$regex": ".*auth#//Role"},
  7. "$ref": {"$regex": "^59bb208006149f50bb32f76f4900c962.*"}
  8. }
  9. }
  10. }
  11. }

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

  1. {
  2. "contents": {
  3. "eClass": "auth#//User",
  4. "roles": {
  5. "$elemMatch": {
  6. "eClass": {"$regex": ".*auth#//Role"}
  7. }
  8. }
  9. }
  10. }

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

bvjveswy

bvjveswy1#

此查询有效。

  1. {
  2. "selector": {
  3. "contents": {
  4. "eClass": "auth#//User",
  5. "roles": {
  6. "$elemMatch": {
  7. "eClass": {
  8. "$regex": ".*auth#//Role"
  9. },
  10. "\\$ref": {
  11. "$regex": ".*59bb208006149f50bb32f76f4900c962.*"
  12. }
  13. }
  14. }
  15. }
  16. }
  17. }

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

展开查看全部

相关问题