Skip to content
Advertisement

Firestore FieldValue.increment()

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

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement