I dont know what is this thing is called but i want to get a refrence of it in android so i want to know what exactly is this thing is called , please check the image down
im taking about this line above "Quote" , whaat is this line is called and how do i get a databse refrence of it in android and really sorry for that bad handwriting though
right now i want to get refrence of 'Quote" im doing it like this
databaseReference = FirebaseDatabase.getInstance().getReference("Quotes");
but how can i get a refrence of that line above"Quote"
databaseReference = FirebaseDatabase.getInstance().getReference("What should i put here to get that refrence ?");
Seems you are using realtime database that is called firebase reference url
you can try as:
import { getDatabase, ref, child, get } from "firebase/database";
const dbRef = ref(getDatabase());
get(child(dbRef, `users/${userId}`)).then((snapshot) => {
if (snapshot.exists()) {
console.log(snapshot.val());
} else {
console.log("No data available");
}
}).catch((error) => {
console.error(error);
});
You can find your Realtime Database URL in the Realtime Database section of the Firebase console.
Depending on the location of the database, the database URL will be in one of the following forms: https:// DATABASE_NAME . firebaseio.com (for databases in us-central1 ) for more details on it you can access the documentation on
https://firebase.google.com/docs/database/web/read-and-write
If you want to get a reference to the root of the database, you can call getReference without any value:
rootReference = FirebaseDatabase.getInstance().getReference();
Also see the documentation for getReference() without parameters, which says:
public DatabaseReference getReference ()
Gets a DatabaseReference for the database root node.
Returns: A DatabaseReference pointing to the root node.
Related
I have the following document
and I have set the following rules
Every time I try to read the document using the Android SDK
FirebaseFirestore db = FirebaseFirestore.getInstance();
db.collection("users").get().addOnCompleteListener(appExecutors
.networkIO(),
task -> {});
I am getting this error
"com.google.firebase.firestore.FirebaseFirestoreException: PERMISSION_DENIED: Missing or insufficient permissions."
I am not sure what is wrong is it the rules or the Android call.
It looks like you meant to type resource.data.author_id instead of resource.data.author_d in the rule.
This code is trying to access every document in the entire users collection:
db.collection("users").get()
If there any any document in that collection that violates the security rules you set up, then it will fail.
Did you instead intend to try to access the single document that the user is supposed to have access to?
I think you can fix this from firebase consol. You just need to sllow access to all user. As I remember by default there was allowed only authorized users.
It seems that I had to add a where close in my code
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
FirebaseFirestore.setLoggingEnabled(true);
FirebaseFirestore db = FirebaseFirestore.getInstance();
db.collection("users").whereEqualTo("authorId",user.getUid()).get().addOnCompleteListener(appExecutors.networkIO(),task -> {});
I am trying to write to my Firebase database however nothing is happening when doing so. Despite adding an onCompleteListener, nothing returns.
I am creating my custom object, and then trying to put that in my database.
Declaring the database:
DatabaseReference mDatabase;
In onCreate:
mDatabase = FirebaseDatabase.getInstance().getReference(); // This returns the correct URL for my project
My code for creating the object is:
Party party = new Party(partyName, partyDescription, userUID, new ArrayList<PartyUser>(), isExplicitAllowedSwitch.isChecked());
My code to assign this to my database is:
mDatabase.child("party").child("1").setValue(party);
Rules:
{
"rules": {
".read": true,
".write": true
}
}
Also, I have noticed (this may not be related to the issue but..) That I can uninstall my app from my phone, reinstall it and it remembers the user that signed in with FirebaseAuth and even if I delete the user entirely!
The strange thing is that even if I set the value to something like "Hello", the same result occurs.
I'm trying to learn how to connect my android application to the firebase database. I've tried the following code:
mDatabase = FirebaseDatabase.getInstance().getReference();
productCloudEndPoint = mDatabase.child("Sample");
productCloudEndPoint.push().setValue("Hello World");
However, nothing gets written when I look at the Firebase console. I have also set the rules.
{
"rules": {
".read": true,
".write": true
}
}
Am I missing something? Thanks
I had the same issue and the problem was that I was using the simulator. You have to use a physical device.
Do not use push method when you are using set() method, set() method would set the value to the reference.
ex:
<database-ref>/users/{UserId}/
username: {name}
Query would be:
mDatabase.child("users").child(userId).child("username").setValue(name);
In your case :
mDB.child("sample").setValue("Hello World");
While push method used to post new custom object, Firebase generates unique id and save into list of such objects.
NOTE: Push() method is used fro javaScript.
Example :
You have user object with properties like
Class User{
String name;
String email;
}
To save such object, you can simply use push() method.
Firebase will save it with a unique Id auto generated.
<db-ref>/users/{uniqueId}/
For JAVA: equivalent method is put() method.
I created my firebase console project and want to use real time database. I am able to add data using my model class (On Register Activity). But now i want to retrieve the same data in my HomeActivtiy.
Firebase is only providing valueChangeListener or addValueListener. But by the time i reach HomeActivity, and set the listener. Data has already changed and my Datasnapshot return null object on onDataChanged()
I am using Firebase version 3 - android
I want to do a get request to my "users" node, where I need data instead of just Database reference. is it possible in Firebase?
Are you sure your reference is correct? If you are using an addValueEventListener on the HomeActivity then your value should also change in the HomeActivity (I assume you are getting a list of registrations).
Make your reference point to parent node of where the registrations are happening.
You can also prove yourself correct or wrong by adding an addOnSuccessListener after saving the registration data.
db.updateChildren(childUpdates).addOnSuccessListener(new OnSuccessListener<Void>() {
#Override
public void onSuccess(Void aVoid) {
finish();
}
});
I read the firebase documentation: https://firebase.google.com/docs/database/android/retrieve-data
And I am still confused, on how to properly query just 1 object from my Firebase database.
Here is the lines of code I have written.
private Firebase mRef;
And in on start:
#Override
protected void onStart()
{
super.onStart();
//Firebase
mRef = new Firebase("my database url");
}
Then in onCreate or in onStart() I use this line:
Query myQuery= mRef.child("key to my DataObject");
But I get an error in that line, and the solution it provides me is:
change or migrate myQuery to com.firebase.client.Firebase
I am wondering which Query am I suppose to import? I have currently imported:
import com.google.firebase.database.Query;
Also, when I query an object, does something in my database have to change in order for me to retrieve objects?
Hopefully someone can provide clear and explicit example code Or steps to show how you query an object (im assuming you can just write a for loop to get a list of objects back).
Thanks
Assume your Firebase database has below structure:
{
"users" : {...}
}
then, to get reference of users, you should code as:
DatabaseReference mDatabaseReferenceUsers; = FirebaseDatabase.getInstance().getReference("users");
Now, If your users object contains a list, then you need to use push() method to get unique key and then set value as below:
String key = mDatabaseReferenceUsers.push().getKey();
mDatabaseReferenceUsers.child(key).setValue(new User("Bob", 27));