0

I'm trying to use firebase.firestore.FieldValue.increment(), but FieldValue.increment() method is not available. I have attached an image contain available methods for firestore. This is my import:

import firebase from "../../firebase/firebase_config"
//Usage
increment = firebase.firestore.FieldValue.increment(1);

Please assist, maybe I am missing something here. Firestore Documentation

Image of firebase.firestore.methods()

EDIT 2: Below is the Firebase config import

import firebase from 'firebase/app';
firebaseConfig ={
...
}
const app = firebase.initializeApp(firebaseConfig);
export default app;

I did tried Doug's export and it worked, but I'm wondering why after calling initializeApp, the FieldValue is no longer available. Doug's

import firebase from "firebase/app"

firebase.firestore.FieldValue.increment(1);
gmnoob
  • 37
  • 7

1 Answers1

1

If you want to use FieldValue.increment(), you have to use the export from firebase/app. Whatever your app is in that screenshot (we can't see exactly what it is) isn't the same thing as the firebase exported from "firebase/app".

For version 8.x of Firebase SDKs:

import firebase from "firebase/app"

firebase.firestore.FieldValue.increment(1);

If you're doing something other than this, it won't work.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • Thanks @Doug, I was able to increment using what you provided, I make an edit to ask why after calling `initializeApp`, the FieldValue is no longer available – gmnoob Dec 13 '20 at 14:30
  • The `app` you get from calling `initializeApp` is not equivalent to the `firebase` that's exported from fireabse/app. You have to use the exported symbol. – Doug Stevenson Dec 13 '20 at 16:24