Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to add or retrieve results

I am using firebase web SDK, as my project is still on expo

I can't seem to add or get any results from firestore. No error is thrown, nothing is shown, nothing is saved also.

import * as firebase from 'firebase'
import firestore from 'firebase/firestore'

var config = {
  apiKey: "xxxxxxxxxxxxxxxxxx",
  authDomain: "xxxxxxxxxxxxxxxxxx",
  databaseURL: "xxxxxxxxxxxxxxxxxx",
  projectId: "xxxxxxxxxxxxxxxxxx",
  storageBucket: "xxxxxxxxxxxxxxxxxx",
  messagingSenderId: "xxxxxxxxxxxxxxxxxx"
};

firebase.initializeApp(config);

var db = firebase.firestore();

var docRef = db.collection('users').doc('alovelace');

var setAda = docRef.set({
    first: 'Ada',
    last: 'Lovelace',
    born: 1815
})

anyone having the same issue? someone knows how to fix it?

like image 977
fweffort Avatar asked Oct 08 '17 16:10

fweffort


2 Answers

I found a solution that is compatible with Expo just run:

npm i -S firebase @firebase/firestore

and add to your code

import  * as firebase from 'firebase';
import '@firebase/firestore';

now you can use

firebase.firestore()

Hope it helps!

like image 162
Gonzalo Cañada Avatar answered Nov 15 '22 08:11

Gonzalo Cañada


Try to use react-native-firebase, it is the officially recommended React Native library for Cloud Firestore.

like image 21
Eugene Alitz Avatar answered Nov 15 '22 10:11

Eugene Alitz