*Angular:6.1.0*
*Firebase:5.3.1*
*AngularFire:5.0.0-rc.11*
@ionic/angular:4.0.0-beta.1
Steps to set up and reproduce
I have FirebaseService which should update appropriate data, in similar way like push works with arrays.
So my constructor:
constructor(public firestore: AngularFirestore) { }
then I have function which make update:
this.firestore.collection(<collectionName>).doc(<docID>).update({'answers.1': <AnswersObject>});
I should have have answers with ids 0, 1(updated), 2, 3 etc
I have only 1 object inside answers with id 1
For array modifications you should use FieldValue.arrayRemove / arrayUnion; see Todd's blog post and the reference for the JS SDK.
Is there an example of how to do this with angularfire2 or should we use the native SDK?
Just leaving the "obvious" answer on how to do this using just the native typescript firestore apis for those confused. (I was for like 20 minutes until I stopped being dumb)
import { firestore } from 'firebase';
//...
this.firestore.collection(<collectionName>).doc(<docID>).update({
answers: firestore.FieldValue.arrayUnion(<AnswersObject>)
});
I get a warning when importing all of firestore:
It looks like you're using the development build of the Firebase JS SDK.
When deploying Firebase apps to production, it is advisable to only import
the individual SDK components you intend to use.
For the module builds, these are available in the following manner
(replace <PACKAGE> with the name of a component - i.e. auth, database, etc):
CommonJS Modules:
const firebase = require('firebase/app');
require('firebase/<PACKAGE>');
ES Modules:
import firebase from 'firebase/app';
import 'firebase/<PACKAGE>';
Typescript:
import * as firebase from 'firebase/app';
import 'firebase/<PACKAGE>';
VSCode and all its package management doesn't throw an error when I try:
import { FieldValue } from 'firebase/firestore'; but ng build doesn't like this.
Is there a way to import just FieldValue? Is there a reason why the FieldValue class isn't available as an export?
I get a warning when importing all of
firestore:It looks like you're using the development build of the Firebase JS SDK. When deploying Firebase apps to production, it is advisable to only import the individual SDK components you intend to use. For the module builds, these are available in the following manner (replace <PACKAGE> with the name of a component - i.e. auth, database, etc): CommonJS Modules: const firebase = require('firebase/app'); require('firebase/<PACKAGE>'); ES Modules: import firebase from 'firebase/app'; import 'firebase/<PACKAGE>'; Typescript: import * as firebase from 'firebase/app'; import 'firebase/<PACKAGE>';VSCode and all its package management doesn't throw an error when I try:
import { FieldValue } from 'firebase/firestore';butng builddoesn't like this.Is there a way to import just FieldValue? Is there a reason why the
FieldValueclass isn't available as an export?
Did you find a solution for your question?
Most helpful comment
Just leaving the "obvious" answer on how to do this using just the native typescript firestore apis for those confused. (I was for like 20 minutes until I stopped being dumb)