import firebase from "../firebase";
import React, { useState, useEffect } from "react";
import { useLocation } from "react-router-dom";
const Result = (props) => {
const { state } = useLocation();
const { exam, category, councelling, branch, gender, rank } = state.state;
const [result, setResult] = useState([]);
const db = firebase.firestore();
const que = category + "_" + gender + "_CR";
const docref = db
.collection(exam)
.doc("2019-2020")
.collection("RankAnalysis")
.where(
(firebase.firestore.FieldPath.documentId()
.toString()
.substring(
firebase.firestore.FieldPath.documentId().toString().length -
branch.length
),
"==",
branch)
)
.where(rank, "<", que);
useEffect(() => {
const fetchData = async () => {
docref
.get()
.then((querySelector) => {
querySelector.forEach((doc) => {
console.log(doc.data());
});
})
.catch((error) => {
console.log("Error getting documents: ", error);
});
};
fetchData();
}, [docref]);
return (
<div>
<h1>{exam}</h1>
<h1>{branch}</h1>
<h1>{category}</h1>
<h1>{gender}</h1>
<h1>{councelling}</h1>
<h1>{rank}</h1>
</div>
);
};
export default Result;
The point is that I want to get the documents from firestore which specifically contains a substring (i.e., branch) at the end, so I used fieldpath.documentId() which returns a fieldpath(I converted it into a string), But Nothing seems to be worked out. the database is structured like:-
The document name be like AAAACSE i want to get the documents which contains a substring "CSE" (dynamic).