Hello I am new and learning ReactJS. I am writing the code for matching the model text from my code to firebase Realtime database model text. The problem i got in this is I have store my model text in state and define it like this var modelTxt = this.state.models
. and write my firebase database query like this. and import it like this import { getDatabase, ref, get, orderByChild } from "firebase/database";
my database structure is like this :
{
070921210001{
"Model": "modelName"
}
}
My code
var modelTxt = this.state.models
console.log(modelTxt)
const dbRef = ref(getDatabase("/"));
get(orderByChild(dbRef, `{"Model"}`)).equalTo(modelTxt).once("value", function (snapshot) {
if (snapshot.exists()) {
console.log(snapshot.val());
} else {
console.log("No data available");
}
})
.catch((error) => {
console.error(error);
});