Getting could not invode RNFirebaseFirestore.documentSet null No virtual method Set - react-native-firebase

Please find the attached screenshot for exact error. I'm getting this error when I'm trying to set the data to firestore. Following is the code
import firebase from 'react-native-firebase';
export function initializeFirestore() {
firebase
.firestore()
.collection('communities')
.doc('communityname')
.collection('members')
.doc('memberid')
.set({ field1: 'value1' })
.then(function(docRef) {})
.catch(function(error) {
console.error('Error updating userChannel : ', error);
});
}
screenshot

I'm not sure if you got your answer but, the only workaround I've been seeing is to downgrade firebase-firestore to 17.1.5
in app level Build.gradle file add
implementation "com.google.firebase:firebase-firestore:17.1.5"
I got the answer from here

Related

Vue Firebase / Firestore Duplicates

I am trying to go through a tutorial (link below) to learn vue and firebase. There is a main dashboard page with a list of components, and I have gotten that to display a list of employees. Then there is a view employee component. When I started to build that, and just loaded data, I started getting this error:
Uncaught FirebaseError {code: "app/duplicate-app", message: "Firebase:
Firebase App named '[DEFAULT]' already exists (app/duplicate-app).",
name: "[DEFAULT]", stack: "[DEFAULT]: Firebase: Firebase App named
'[DEFAULT]…0)↵ at fn (http://localhost:8081/app.js:89:20)"}
The firebase code I added to view employee is as follows:
import db from "./firebaseInit.js";
export default {
name: "view-employee",
data() {
return {
employee_id: null,
name: null,
dept: null,
position: null
};
},
beforeRouteEnter(to, from, next) {
db
.collection("employees")
.where("employee_id", "==", to.params.employee_id),
get().then(querySnapShot => {
querySnapShot.forEach(doc => {
next(vm => {
vm.employee_id = doc.data().employee_id
vm.name = doc.data().name
vm.dept = doc.data().dept
vm.position = doc.data().position
})
});
});
}
};
When I comment out this script on the view employee page, the error goes away. From what I can tell, I have done everything the same as the tutorial in the video, and as my buddy who did the same project.
There is also a warning, which may be related, which states as follows:
There are multiple modules with names that only differ in casing. This
can lead to unexpected behavior when compiling on a filesystem with
other case-semantic. Use equal casing. Compare these module
identifiers: *
/Users/jdurell/code/employeemanager/node_modules/babel-loader/lib/index.js!/Users/jdurell/code/employeemanager/src/components/FirebaseInit.js
I am working on this tutorial / project:
https://www.youtube.com/watch?v=cjEzK4me1k8&index=4&list=PLillGF-RfqbYsOOycB67Raf9dwmL6Y31M
Nemesv had the correct answer. It was a casing issue. I had the issue FirebaseInit on the other component. I changed that to firebaseInit so it was the same case on both components, and the error resolved. Thanks!

React native firebase database on value change not triggered

I have a react native app and using firebase database.
I try to use the on or once functions to get items from database but I don't know what I am doing wrong because I don't get any data.
This is my code to get data from firebase database:
firebase.database().ref("messages/").once('value', snapshot => {console.log("snapshot value", snapshot)});
I try the command from above also with on instead of once and same result. The console.log is never called.
When I am adding messages everything it's ok and the messages appear in the firebase console. For adding messages I am doing like this:
firebase.database().ref("messages/").push(message);
For firebase I am using this library: rnfirebase.io
This are the versions used:
React: 16.6.0-alpha.8af6728
React native: 0.57.4
React native firebase: 5.0.0
The Firebase once returns a promise so you have to use then after using value.
The code should be like
firebase.database().ref('tableNameHere').once('value').then(snapshot => {
if(snapshot.exists()){
console.log(snapshot.val());
}
}).catch(err => console.log(err));
when using on value the function will invoke on change in value like on CRUD operation
firebase.database().ref('tableNameHere').on('value', snapshot => {
if(snapshot.exists()){
console.log(snapshot.val());
}
},(err) => console.log(err))

Firebase functions - Deploy Completed but doesn't exist in Firebase

Follow the guide of using Cloud Functions with Firebase.
Setup environment
setup project in Firebase
Created function
command prompt writes that function deployed, but firebase is empty.
I am new with deploying functions so I am sure that it is stupid question and I think I did something wrong in setting up but I checked three times different guides and it looks everything done right. So please if you know what the problem it is can be?
I used this guide and there I done everything till initializing the project
https://firebase.google.com/docs/functions/get-started
After that in index.js I wrote a function
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(function.config().firebase);
export.sendNotification = functions.database
.ref('/notifications/{user_id}/{notification_id}')
.onWrite(event => {
conts user_id = event.params.user_id;
const notification = event.params.notification_id;
if(!event.data.val()){
return console.log('A notification has been deleted ', notification_id);
}
const payload = {
notification: {
title: "Friend Request",
body: "Received new Friend Request",
icon: "default"
}
};
return admin.messaging().sendToDevice(/*Token*/, payload).then(response =>{
console.log('');
});
});
And with the command
firebase deploy
I tried to deploy function
But in firebase cattegory "Function" it is still empty
Error in CMD
There is syntax error, Please change below line in your code
admin.initializeApp(function.config().firebase);
to
admin.initializeApp(functions.config().firebase);
I'm quite late here but it might help somebody else. You're right, it is typo. The correct command is:
exports
not
export

In Angular (using angularfire2 and typescript) how do you get types on errors thrown when using firestore?

Angularfire2 makes it easy to use firestore. But I can't find any documentation on how to get typings for errors thrown?
For example you can delete a document with:
return this.itemsCollection.doc(idOfItem).delete();
This returns a promise. When/if it fails, how do I get types on the error code?
I imagine I have to cast is to something?
I tried to read the documenation on firebase.google.com, and think I have found the ref file here: https://firebase.google.com/docs/reference/android/com/google/firebase/firestore/FirebaseFirestoreException.Code
But how do I cast the error so I get typings in typescript?
So I figured out you can do it like this:
import * as firebase from 'firebase';
this.itemsCollection.doc(idOfItem).delete()
.catch(err) => {
const error = err as firebase.FirebaseError;
// You can now check against errors from the documentation
// https://firebase.google.com/docs/reference/js/firebase.firestore.FirestoreError
if (error.code === 'permission-denied') {
console.log('The user does not have access to this');
}
}
The code is a string, so I don't know if there is a great advantage of the types, but well to answer my own question :)

Image upload with Firebase React Native

I want to upload an image to Firebase Storage from a React Native app, the Firebase web sdk only works on iOS so I am giving Firebase React Native a go. The docs are empty but someone pointed my to the old docs so my code looks like this.
firebase.storage().ref('/rn-firebase2.jpg').putFile(imgFile.uri)
.on('state_changed', snapshot => {
//Current upload state
console.log('state_changed: ', snapshot);
}, err => {
//Error unsubscribe();
console.log('err: ', err);
}, uploadedFile => {
//Success unsubscribe();
console.log('uploadedFile: ', uploadedFile);
});
When ran, I get
"Possible Unhandled Promise Rejection (id: 0):". A file is uploaded to
the Cloud Storage but it unusable.
Anyone has successfully gotten this to work on iOS and Android? Any help would be much appreciated, thanks!

Resources