Monday 27 August 2018

mongodb - Updating a document field in mongo based on another field's value



Suppose I have two fields F1 and F2. I want to update F1 to become F1 + ", " + F2. Can I do so with a single update command in mongo?


Answer



No, you can't do that. You can't use expressions in mongodb updates. The only way is to fetch this document to the client, compose new field value there and issue a prepared update statement.


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...