2👍
✅
According to this post,
When you pass an object to Firebase, the values of the properties can
be a value ornull
(in which case the property will be removed). They
can not beundefined
, which is what you’re passing in according to the
error.
Your error message suggests that post.video
‘s value is undefined
. You can use logical-or to provide a fallback value like so:
video: post.video || null,
That means whenever post.video
has a false-y value, the expression will evaluate to null
. That could catch empty string or numeric 0, though. To be more precisely correct, you should use
video: typeof post.video === 'undefined' ? null : post.video,
If you need to do this check for many values, you can write a function for it:
function nullIfUndefined(value) {
return typeof value === 'undefined' ? null : value;
}
then your expression would just be
video: nullIfUndefined(post.video),
Source:stackexchange.com