Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

102
Views
I want to display only documents with matching fields in firebase

As in the title, I want to show only documents with matching fields in Firebase.

Now my code using jquery looks like this:

const db = firebase.firestore();

db.collection('product').get().then((product)=>{
    product.forEach((doc)=>{
        var li = "";
        console.log(doc.data())
        if(topic == doc.data().topic){
            li = `
                <div>
                    <img class="${img}" src="${doc.data().img}">
                    <p class="text-500 text-white">${doc.data().title}</p>
                </div>
            `
        }else{
            li = `
                <div>
                    <img class="${img}" src="${doc.data().img}">
                    <p class="text-500 text-white">${doc.data().title}</p>
                </div>
            `
        }
        $(`.app`).append(li)
    })
});
<div class="app"></div>

All documents are now available. For example, if the current URL is "https://example.com?topic=firebase", I want to display only the contents of the documents with the topic field firebase in the documents in a collection called product.

Thank you in advance.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

To get the value of the URL parameter "topic", try this:

function getParameterByName(name, url) {
    if (!url) url = window.location.href;
    name = name.replace(/[\[\]]/g, '\\$&');
    var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, ' '));
}

const topic = getParameterByName("topic", window.location.href);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!