如何获取数组中不包含具有特定值的对象的文档
How to obtain documents which don't contain object with specific value inside an array
比如我有两个文件:
{
communication: "some data 1"
users: [
{
name: 'Peter',
role: 'admin'
gender: 'male'
},
{
name: 'John',
role: 'guest'
gender: 'male'
}
]
}
{
communication: "some data 2"
users: [
{
name: 'Kollins',
role: 'admin'
gender: 'male'
},
{
name: 'Steve',
role: 'moderator'
gender: 'male'
}
]
}
最后,我必须获取 users
数组中没有 user
和 role: 'guest'
的文档。基于两个文档的示例,我必须获得第二个。
伪代码是这样的:
select * from bucket where users.role = 'guest' is missing
您需要使用 ARRAY
and check if there is a user with NOT EXISTS
映射用户数组
SELECT * FROM bucket WHERE NOT EXISTS ARRAY users FOR user IN users
WHEN user.role='guest' END
比如我有两个文件:
{
communication: "some data 1"
users: [
{
name: 'Peter',
role: 'admin'
gender: 'male'
},
{
name: 'John',
role: 'guest'
gender: 'male'
}
]
}
{
communication: "some data 2"
users: [
{
name: 'Kollins',
role: 'admin'
gender: 'male'
},
{
name: 'Steve',
role: 'moderator'
gender: 'male'
}
]
}
最后,我必须获取 users
数组中没有 user
和 role: 'guest'
的文档。基于两个文档的示例,我必须获得第二个。
伪代码是这样的:
select * from bucket where users.role = 'guest' is missing
您需要使用 ARRAY
and check if there is a user with NOT EXISTS
SELECT * FROM bucket WHERE NOT EXISTS ARRAY users FOR user IN users
WHEN user.role='guest' END