Stock Price Checker mongoDB logic

https://learn.freecodecamp.org/information-security-and-quality-assurance/information-security-and-quality-assurance-projects/stock-price-checker

Im currently in the mist of building my price checker.
I realize while making this app after you receive your results back from the api and you need to update your database based on the data already there in mongoDB.
Meaning specifically I would need to add to the like count if user ip address has not be stored in the database.
I can find the document and based on the returned document I can place another request to update/modify using either callback or promises. But for me this logic seems wrong as I would be accessing the database twice.
My question is this the right method to achieve this? or is there way I can place this logic in the mongoDB request so I do not have to access the database twice?

I looked into mongodb " Aggregation" and conditionals, but I could not find a good answer on this.

Anyways any thoughts on this would be appreciated.

Jay

findAndUpdate() works wonders, and then if doc is not there it can insert, also can update if the IP is not there. May need to use mongoose.

1 Like

Thanks for the advice. I ended up solving it. But was looking for a more concise solution.
I probably will use mongoose more in the future where I need to modify the data on the fly . Woulda made my life easier. But findAndUpdate() did work for me :)…