Hi, I’m working on a project where I need to conditionally add an ! to the end of the users name if its _id matches the one given. I think I should be able to do this using $concat, but I’ve tried playing around with this in mongo playground, but I can’t seem to get it to work. I would really appreciate any help or advice. Thank you!
Based off the playground link, I assume the provided value in this case is 12 in which you want the name "John" to turn into "John!" - However, please correct me if I am wrong here.
Would the following work for you? I only tested it on the playground sample documents:
Thank you for your response! This worked. I have a question though. Is there a way to conditionally $set/ change where only the user whose _id matches data would be updated? I’m pretty new to this, but it seems like this could be an expensive process. Would a simple $push and $pull be less energy/ performance intensive?