【发布时间】:2018-01-23 02:42:08
【问题描述】:
我正在使用带有 react native 的 firestore,如下所示,但是在运行我的应用程序时,数据不会添加到云中。不知道为什么,请帮助我理解这里的实际问题。
componentWillMount() {
console.log('Test1');
firebase.initializeApp({
apiKey: 'xxxxxxx',
authDomain: 'testing-8ex763xxxxxxxxxxxxxx',
databaseURL: 'https://testing-8e76xxxo.com',
projectId: 'testing-xxxxx',
storageBucket: 'testing-8xxxxx.com',
messagingSenderId: '73664xxx042'
});
firebase.firestore().enablePersistence()
.then(function() {
// Initialize Cloud Firestore through firebase
var db = firebase.firestore();
console.log('Test3', db);
db.collection('us').add({
first: 'hai',
last: '111',
born: 1815
})
.then(function(docRef) {
console.log("Document written with ID: ", docRef.id);
})
.catch(function(error) {
console.error("Error adding document: ", error);
});
})
.catch(function(err) {
if (err.code == 'failed-precondition') {
// Multiple tabs open, persistence can only be enabled
// in one tab at a a time.
// ...
} else if (err.code == 'unimplemented') {
// The current browser does not support all of the
// features required to enable persistence
// ...
}
});
}
【问题讨论】:
-
错误信息是什么?
-
我没有收到任何错误消息,同时我的数据不在云 Firestore 中。 Cloud Firestore 中未创建任何集合。感谢您的帮助。
-
尝试将
db.collection('us').add()移到外部enablePersistence()承诺。 -
我也试过了,弗兰克,(没有 enablePersistence)但没有运气。还是不行。
标签: javascript react-native google-cloud-firestore