Using relational db as an example, given two tables like below, where when rows in tableA
and tableB
have the same values, they represent the same "thing" but in different "state". So for ID=1, this thing has gone through stage1 and 2. But for ID=2, this thing has only gone through stage1.
tableA (Id, columnA, columnB)
1, "a", "b"
2, "x", "y"
3, "z", "a"
tableB (Id, columnA, columnB)
1, "e", "f"
I want to find all the rows from tableA
that don't exist in tableB
.
select a.*
from tableA a
left join
tableB b
on a.Id = b.Id
where b.Id is null
So above SQL will show rows 2 and 3 from tableA.
How can I do similar things in CouchDB? Say I have 4 docs that look like below.
{ "_id":"a-1", "type":"A", "correlation_id": "1" }
{ "_id":"a-2", "type":"A", "correlation_id": "2" }
{ "_id":"a-3", "type":"A", "correlation_id": "3" }
{ "_id":"b-1", "type":"B", "correlation_id": "1" }
How can I create a view that only show docs id = a-2 and a-3
? I don't want to filter, just want to show all docs that haven't got type B
. I could kinda do a group by and count(*)
equivalent with view, but I can't do a group by, having count(*) = 1
equivalent.
I'm using CouchDB 3.0.