Hi, I'm running into an issue when trying to clear a specific field using
payload.update
, my call looks like
const updatedDoc = await req.payload.update({
collectionName: 'foo',
id: 'someId',
data: {
nonRequiredStringFieldToClear: undefined
}
});
I'm assuming the Local API doesn't know that
nonRequiredStringFieldToClear
is even being specified since its value is
undefined
. Also unable to pass
null
as the generated type for the field is
string | undefined
.
A workaround so far is to set
nonRequiredStringFieldToClear: ""
but actually clearing the field would be nicer.
Has anyone else run into this? Thanks!
Noting we could also use the mongoose model with
$unset
, but, for now, just going to set to an empty string here for simplicity
Interesting, yeah I think null would be the preferred value to save. Undefined will not work because we merge existing data with incoming data.
But like you said the type is not allowing null, which seems like it should.
Hey @allannnc did this get resolved?
Hey @jesschow not afaik
Stuck with the workaround of passing "empty" non-null values
@allannnc hmm not ideal... could you throw this information into an issue over on GitHub for us?
https://github.com/payloadcms/payload/issueswill reproduce and create this issue if needed!
would this be a bug report or feature request?
for reference: this does not clear the
code
field, acts as if
code
was never passed in
data
and this is not allowed:
so, this is the workaround
@allannnc bug report please 👍
@allannnc awesome thank you, we'll get this resolved soon 👍
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.