问题
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);
回答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.
来源:https://stackoverflow.com/questions/65273383/firestore-fieldvalue-increment