Hope the title topic wasn’t too misleading, let me explain the problem a bit more:
- we do have a collection called
Matches
- it always has two fields kit1 and kit2 which represent users DNA kits from anotherKits
collection (foreign key in SQL lingo). - I have a list of kits that can be in either kit1 or kit2, that can be solved in two separate queries and using $in
- But I want to find all docs where either kit1 or kit2 is in that list of kits and there is only a single doc for this specific kit1 / kit2 combination
Not sure if anyone understands, so I better give an example:
List of kits: [‘AA’, ‘BB’, ‘CC’]
Matches docs that I’m trying to find (as their count will be === 1):
{ kit1: ‘AA’, kit2’ ABV’, chr: ‘1’ }
{ kit1: ‘XX’, kit2: ‘CC’, chr: ‘5’ }
Matches docs that should be excluded from the result (as their count > 1)"
{ kit1: ‘BB’, kit2: ‘HR’, chr: ‘8’ }
{ kit1: ‘BB’, kit2: ‘HR’, chr: ‘X’ }
I’m not even sure this can be done in MongoDb directly but would appreciate the aggregation been done there as we already have 700,000 docs in Matches and will soon cross 1 million.
Thanks in advance,
Andreas