Question:
Theres a several old questions (2015/2016) about doing an upsert with $inc that has a default value. The consensus seemed to be do multiple DB calls. I’m hoping there is a more modern approach to this now. I’m using Mongo 5.0.9.I found this example that states you can now use $cond in update aggregation pipelines. I tried the following: https://stackoverflow.com/a/62819768/1795570
Trying to convert it to my problem I came up with:
Answer:
You will be able to achieve that with this, you’re missing [] that will help you to use the aggregation framework, then you should have thisYou will be able to achieve that with this, you ‘re missing [] that will help you to use the aggregation framework, then you should have this
If you have better answer, please add a comment about this, thank you!