Couchbase N1QL查询与字典

huangapple go评论70阅读模式
英文:

Couchbase N1QL query with dictionary

问题

在Couchbase中,我有包含以下结构的文档:

{
    "...": "...",
    "members": {
        "*USERID*": {
            "...": "..."
        }
    }
}

现在我想使用N1QL查询来获取所有包含我的用户ID作为members中键的文档。我尝试了许多不同的查询,但未能找到一个有效的N1QL查询。

一个选择所有包含指定用户ID作为members映射键的文档的N1QL查询是什么样的?

英文:

In Couchbase I have documents that contain a dictionary structured like this:

{
    "...": "...",
    "members": {
        "*USERID*": {
            "...": "..."
        }
    }
}

Now I want to use a N1QL Query to get all documents where my user id is in members. I have tried many different queries, but I was not able to find a working N1QL query.

What does a N1QL Query look like that selects all documents with a specified user id as a key in the members map?

答案1

得分: 2

SELECT d.*
FROM default AS d
WHERE d.members.["myuserid"] IS NOT NULL;

OR

SELECT d.*
FROM default AS d
WHERE ANY n IN OBJECT_NAMES(d.members) SATISFIES n = "myuserid" END;

OR

SELECT d.*
FROM default AS d
WHERE ANY n:v IN d.members SATISFIES n = "myuserid" END;

英文:
SELECT d.*
FROM default AS d
WHERE d.`members`.["myuserid"] IS NOT NULL;

OR

SELECT d.*
FROM default AS d
WHERE ANY n IN OBJECT_NAMES(d.`members`) SATISFIES n = "myuserid" END;

OR

SELECT d.*
FROM default AS d
WHERE ANY n:v IN d.`members` SATISFIES n = "myuserid" END;

huangapple
  • 本文由 发表于 2023年1月9日 00:10:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/75049327.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定