每个文档描述客户协议(决策,而非价值),简化:
{
"_id": "123",
"customerID" : "Smith"
"agreement": [
{"agreementType":"A"
"agreementValue":"T"},
{"agreementType":"B"
"agreementValue":"T"}]
}
{
"_id": "124",
"customerID" : "Smith"
"agreement": [
{"agreementType":"A"
"agreementValue":"F"},
{"agreementType":"B"
"agreementValue":"T"}]
}
{
"_id": "125",
"customerID" : "Brown"
"agreement": [
{"agreementType":"A"
"agreementValue":"T"},
{"agreementType":"B"
"agreementValue":"T"}]
}
{
"_id": "126",
"customerID" : "Brown"
"agreement": [
{"agreementType":"A"
"agreementValue":"T"},
{"agreementType":"B"
"agreementValue":"T"}]
}
我需要查询所有对同一agreementType具有不同agreementValues的客户(例如,单个客户同意,第二天不同意)。它应该返回Smith(agreementType=A的不同值)。
目前我可以找到所有的重复,但不能限制到那些不同的价值观
1条答案
按热度按时间wz3gfoph1#
您可以
$unwind
agreement
数组并执行$group
以获得agreementValue
的不同值。$match
,其中$size
大于1,以获得所需的记录。Mongo Playground