Q: UPDATE with undefined value

when I write an update statement, meet a question:
I want to update serial properties at once, so I use string joint an update statement.
like this:

const sqlStr = `UPDATE ${this.bucket._name} USE KEYS \"${id}\" SET ${fieldStr} RETURNING ${this.bucket._name}.*`;

the fieldStr is a for () statements like:

fieldStr += `${key} = ${value}`;

but if haven’t pass optional arguments, the statement like this:

UPDATE guoxue USE KEYS "Category::1534898823656::nbb2" SET  name = "lesson",order = undefined,valid = undefined RETURNING guoxue.*

how can I ignore the undefined property when executing the update.


Best wishes

While doing this if value is undefined don’t add to the string and use adhoc=true. Once you added to UPDATE no way you can avoid.

thanks for you reply.

Hi @angular, just a note to say that for single document updates like this, it’s going to be more efficient to use the key-value SDK rather than N1QL. Please see the SDK docs for more details.

thanks! graham.pople