When querying MongoDB is it possible to perform a query and if it isn't matched perform a second query. I could perform an $or which will do booth queries and return the results for booth but I only need to perform the second query if the first doesn't match.
Let say my BSON documents look like:
[
{"id": 1, "value": "foo"},
{"id": 2, "value": "bar"}
]
I need to return "id": 1 but if it doesn't exist I need to return "id": 2