How to get the specific data in nested node in Firebase - android-studio

I am trying to get the name of the specific user in my firebase but i can not access since it is nested i used.
orderbychild("userid").equalto(currentuserid)
and try to used toast if it's existed, yes it is existing but when i get the value of name using
String name=datasnapshot.child("name").getvalue.tostring()
My app suddenly crashed

Related

How can I force Firebase Realtime Database URL without "default-rtdb"

My realtime database URL is like https://myprojectid.firebaseio.com
When I start my node.js server I have error message :
#firebase/database: FIREBASE WARNING: Firebase error. Please ensure
that you have the URL of your Firebase Realtime Database instance
configured correctly.
(https://myprojectid-default-rtdb.firebaseio.com/)
My Firebase config is :
# Firebase
apiKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx
authDomain=myprojectid.firebaseapp.com
databaseURL=https://myprojectid.firebaseio.com
projectId=myprojectid
storageBucket=myprojectid.appspot.com
messagingSenderId=00000000000000
appId=1:0000000000000:web:000000000000000
When I'm trying to debug npm library, I can see that namespace is indeed "myprojectid-default-rtdb" but can't find where to change it.
I tried to set databaseURL with query string ?ns=myprojectid but not better.
By searching on Google I could read :
For recently created Firebase projects the default database URI
usually has the format https://
-default-rtdb.firebaseio.com. Databases in projects
created before September 2020 had the default database URI
https://.firebaseio.com. For backward compatibility
reasons, if you don’t specify a database URI, the SDK will use the
project ID defined in the Service Account JSON file to automatically
generate it
Could you help me to find a solution please?
There's no way to change the name of the default database instance that is created in your Firebase project. If your project is on the paid plan, you can add additional database instances where you fully control the name, but not for the default one.
You will have to update your project configuration to use the correct database URL. If the database in the US data center, that'd be:
databaseURL=https://myprojectid-default-rtdb.firebaseio.com

Logic Apps and CosmosDB

So I'm trying to do something I expected to be simple - using Logic App to insert a json object into Cosmos DB.
I've created a CosmosDB (based on Core SQL API) and created a container called Archive with the partition key /username (which is in my json object).
Now to Logic App.
First, I YOLO'ed the simple approach.
Which gave me error: "The input content is invalid because the required properties - 'id; ' - are missing"
But my json object doesnt have an id field. Maybe use the IsUpsert parameter? I dont feel like manipulating my input document to add a field called 'id'.
Which gave me error: "One of the specified inputs is invalid" Okay - feels even worse.
I now tried to use the other logic app connector (Not V2, but the original).
which gave me error: "The partition key supplied in x-ms-partitionkey header has fewer components than defined in the the collection."
I saw that this connector(unlike the V2 one) has a Partition Key Value parameter from UI, which I added to pass the value of my username
which gave me error "The input content is invalid because the required properties - 'id; ' - are missing".
At this point I thought, let me just give the bloody machine what it wants, and so I added "id" to my json object.
and yes that actually worked.
So questions are
With Logic Apps connectors, are you only able to insert json objects into Cosmos DB without that magic field "id" in the message payload?
If the partitioning key is required. Why is it not available from the V2 connector parameter UI?
Thanks.
The v1 version of this thing doesn't have partition key because it's so old, Cosmos didn't have partitioned containers. You will want to use the v2 preview. I think that will go GA at some point here soon because it's been in preview for a while now.
And yes, With Cosmos DB you can't insert anything without it's id so you will need to generate from whatever calls your endpoint and pass it in the body of your http request.

Why are all activities showing Unknown for the User/Actor .NET Server API w/React-JS client components

I am working on a proof of concept with GetStream.io using the .NET server side API to add activities and the react-js client components to render feeds. For some reason every activity is coming into my feeds with Unknown in bold at the top. I assume this is supposed to be the username or something? I read a post about passing in a reference to the user instead of the string userId but the .NET API constructor signature creating a new Activity only takes in a string userId parameter. I have verified that I am passing in a valid userId. Any suggestions on what I am doing wrong here?
Stream stores the unique reference and replaces it at read time. In some complex cases, you need to be able to generate a reference to an existing object and embed that inside of an activity.
Then, can you try this way:
// Since we know their IDs we can create a reference without reading from APIs
var userRef = Users.Ref(userId);
// And then add an activity with these references
var activity = new Activity(userRef, activityAction, message)

Google Cloud Functions Firebase Error The default Firebase app already exists

I am using Google Cloud Functions to write to a Firebase Realtime database (not firestore).
I keep getting an error on the 2nd (second) time the cloud function executes. The first time is OK. But always fails on the 2nd and 3rd and onwards.
Error Message: "The default Firebase app already exists. This means you called initialize_app() more than once without providing an app name as the second argument."
Here is my code:
import firebase_admin
from firebase_admin import db
def my_function(request):
firebase_admin.initialize_app()
firebase_db_path = "/some_path"
ref = db.reference(path = firebase_db_path, app=None, url = "https://blah-blah.firebaseio.com/")
ref.set(json_data)
I am able to avoid the error by wrapping the initialization with an if-else block, but somehow I feel that this implementation is messy (not really graceful). Is there a better way than this?
if not firebase_admin._apps:
firebase_admin.initialize_app()
As the error says:
The default Firebase app already exists. This means you called initialize_app() more than once without providing an app name as the second argument.
You need to call initialize_app() only once as it only needs to be initialized once.
The best solution is to write firebase_admin.initialize_app() outside my_function().

How could I get the Node specific ID in Node-Red?

I've already created a custom node, and I need to get the ID which displays on the INFO tab along with the type before the flow gets deployed.
So that I could use that ID as a unique id, to do CRUD operations.
How could I get this? Any help could be appreciated.
The data you want is available in the oneditsave call back function as follows:
...
oneditsave: function(){
var id = this.id;
...
}
As I said in the comment, you should only create resources to back a node at the point that the node is deployed as it may never be deployed and there is no way to clean up an undeployed node's resources.
The resources should be created in the javascript file so they can be cleaned up using the node.on('close',function(done){})

Resources