1

Hi Everyone of StackOverflow Community,

I have a doubt in an activity that I have to do for homework.

I want to know how I can increment one field in every document that is filtered by a specific condition. My problem is not in the update code, in termes that this number field to increment was a number type (int, float, double,...), but yes when I have to increment that field values (numbers) in a field that has String as a field type.

It give my that error (ScreenShot):

ERROR MongoDB Update

Thanks.

See you,

1 Answers1

0

One way to solve it is like JohnnyHK said in the comment:

You can't do that in a single update; you'd have to find the document, convert the string to number, add 5, convert it back to a string, and update the document with $set.

Another possibility is found in the following question:

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
  • Ok Wai Ha Lee (I know to put the link as a unorganized list with 1item) and I also know ho to make a cite to a comment (I didn't do because I thought it was intuitive) , but how did you put the mention to JohnnyHK? (typing its user profile URL?) – Oriol Cantarell Sala Apr 20 '19 at 18:44
  • Thanks. [Wai Ha Lee](https://stackoverflow.com/users/1364007/wai-ha-lee) !! – Oriol Cantarell Sala Apr 20 '19 at 22:53