• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Mongo 5 findOneAndUpdate aggregation pipeline for default counter value?

Resolved: Mongo 5 findOneAndUpdate aggregation pipeline for default counter value?

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

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:
This however just adds the entire $cond as the value to my document.
Is it possible to do this?

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 this
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 this

If you have better answer, please add a comment about this, thank you!

aggregation mongodb
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: The ‘Access-Control-Allow-Origin’ header contains multiple values ‘*, *’, but only one is allowed. cors error not resolving

02/04/2023

Resolved: SQLSTATE[42S02]: Base table or view not found: 1146 Table ‘crm.email’ doesn’t exist (Connection: mysql, SQL: select count(*) as aggregate from `email`

02/04/2023

Resolved: Regex: Curly braces in reverse? Match X characters before a string?

02/04/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.