I am new to MongoDB. I have worked on Legacy Mainframe and DB2 Database. My requirement is as below - I have a collection say Logs which has fields named as CaseNum, ProcessingStage, body1 and body2. The Documents in collection looks like this
Doc1 - CaseNum: '123', ProcessingStage: 'Start', body1: {data object1}
Doc2 - CaseNum: '123', ProcessingStage: 'Error', body2: {data object2}
Doc3 - CaseNum: '123', ProcessingStage: 'Success', body2: {data object2}
Doc4 - CaseNum: '456', ProcessingStage: 'Start', body1: {data object3}
Doc5 - CaseNum: '456', ProcessingStage: 'Error', body2: {data object4}
Doc6 - CaseNum: '789', ProcessingStage: 'Start', body1: {data object5}
I need to extract body1 field from the document having ProcessingStage as 'Start' where the CaseNum has a 'Error' document and does not have the 'Success' document.
So in this example, the MongoDB query should fetch body1 from Doc4 of CaseNum '456' because it has a 'Error' document Doc5 and does not have the 'Success' document.
CaseNum '123' has an 'Error' document but since it also has a 'Success' document so it fails the desired condition and
CaseNum '789' does not have the 'Error' document so it also fails the desired condition.
My apologies, If I am not able to explain my issue properly. Please help.