I’m making 2 queries to the database.
Right now, if even one of them is undefined, I get the generic ‘not found’ message that is set up. This is because there’s an ‘else’ set up at every DB query where it responds with ‘not found’ if a value is undefined
What I want to achieve:
If one of them is null, I want to add the value ‘nil’.
Example:
field1: nil,
field2: 'value'
If both are null, then I want it to respond with the previously mentioned ‘not found’ message.
What’s a good approach for this?
2
Answers
I think your goal may be achieved using 1 call to the database by using https://www.mongodb.com/docs/manual/reference/operator/aggregation/switch/ but please provide example document structure and what the expected behavior should be in a bit more detailed way.
This is my existing data in the local database.
Following is my Node.js code:
What you are seeing below the output: