question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

arrayUnion with objects produces null values

See original GitHub issue

First 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: image

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: image

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:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
EddyVerbruggencommented, Feb 11, 2019

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).

1reaction
solvemoncommented, Feb 11, 2019

Sure, the results are as expected in the console: image

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found