Firestore FieldValue.increment()

China☆狼群 提交于 2021-01-29 20:16:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!