arrayUnion with objects produces null values
See original GitHub issueFirst of all, thanks for a fantastic library!
I am having some trouble updating an array in my document, using arrayUnion;
note: Just to test the two different versions of the API, I am doing the update operation twice. My imports are as follows:
const firebase = require('nativescript-plugin-firebase')
const fbApp = require('nativescript-plugin-firebase/app')
When I attempt to update my array using a primitive (I have tested string and number), it seems to work fine:
let scan = 1234
console.log('Updating scans with', scan)
driver.update(
{
scans: fbApp.firestore().FieldValue().arrayUnion(scan),
scans2: firebase.firestore.FieldValue.arrayUnion(scan),
}
)
My updated fb store via console:
However, when I change my value to an object, it inserts null
instead:
let scan = {foo: "bar"}
console.log('Updating scans with', scan)
driver.update(
{
scans: fbApp.firestore().FieldValue().arrayUnion(scan),
scans2: firebase.firestore.FieldValue.arrayUnion(scan),
}
)
FB Console:
Any idea what I could be doing wrong here?
(I can work around this by JSON.stringify
-ing my input, but that seems like a slightly silly solution…)
I am using version 7.7.0 and so far am only testing on Android, so I’m not sure if this is a problem on iOS
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
FieldValue.arrayUnion() creates a null value in array at very ...
I am facing issue of an empty value/object being created at the very first post to firebase when i update array using FieldValue....
Read more >ARRAY_UNION_AGG - Snowflake Documentation
The function ignores NULL values in column and in the ARRAYs in column . If column contains only NULL values or the table...
Read more >Class: Array (Ruby 2.6)
Array. Arrays are ordered, integer-indexed collections of any object. ... A useful method if you need to remove nil values from an array...
Read more >Spark SQL, Built-in Functions
array_min(array) - Returns the minimum value in the array. NULL elements are skipped. Examples: > SELECT array_min(array(1, 20, null ...
Read more >How do I compare two arrays in JavaScript?
... and objects are compared by reference and not by value in JavaScript, which means this solution does not produce the desired result:....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for those details, that really helped. Pretty sad I can’t find any official example of using an object with
arrayUnion
, but anyway: got it fixed!On iOS it already worked as expected by the way.
Available in 8.0.0 which will be out later this week(end).
Sure, the results are as expected in the console: