Documentation Home
X DevAPI User Guide for MySQL Shell in Python Mode
Download this Manual
PDF (US Ltr) - 1.2Mb
PDF (A4) - 1.2Mb


10.1.2 Value Expression Strings

Value expression strings are used to compute a value which can then be assigned to a given field or column. This is necessary for both modify() and update(), as well as computing values in documents at insertion time.

An example use of a value expression string would be to increment a counter. The expr() function is used to wrap strings where they would otherwise be interpreted literally. For example, to increment a counter:

// the expression is evaluated on the server
collection.modify('true').set("counter", expr("counter + 1")).execute()

If you do not wrap the string with expr(), it would be assigning the literal string "counter + 1" to the "counter" member:

// equivalent to directly assigning a string: counter = "counter + 1"
collection.modify('true').set("counter", "counter + 1").execute()