I have the following schema in my database:
{
_id: Number,
reagents: [ //Array of objects (embedded) FIND IF certain tag in v_class occurred only once in array
{
_id: Number,
v_class: Array, //A single array (string only): ['TEST','PREMIUM']
},
{
_id: Number,
v_class: Array, //A single array (string only): ['TEST','PREMIUM']
},
{
_id: Number,
v_class: Array, //A single array (string only): ['TEST','PREMIUM']
}
],
other_fields: other_values,
}
The question is all about:
How to find only that documents, where
reagentsfield have only one item (reagent, embedded documents), amongv_classarray field consist the wordPREMIUM.
So from the selected collection above, I want to have only document with _id: 2 because it's the only document where reagents field have THE ONLY document, where in field called v_class word PREMIUM occurring only once.
UPD: I have achieved a bit simple results after $group stage, MongoPlayground (after group). So as for now, I still need to find docs where v_class array field occurring PREMIUM value exactly once in it's array`
UPD2: I have new version has appeared. MongoPlayground. This query is fine, but it shows all the PREMIUM except that occurred just once.
PREMIUMin thev_classarray ofreagents.v_classarray field will have only["PREMIUM"]value, it means that I need to find only one doc, withv_class= consistPREMIUMso it could be like `['X', 'PREMIUM']