英文:
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;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论