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

144
Views
"documentRef" is not a valid DocumentReference showing
async function process_tasks() {
    let campaignsRef = db.collection('campaigns')
    let activeRef = await campaignsRef.where('active', '==', true).select().get();
    for (campaign of activeRef.docs) {
        console.log(campaign.id);
        (CHOICE 1) let tasksRef = await campaignsRef.doc(campaign.id).collection('tasks').get();
        (CHOICE 2) let tasksRef = await campaign.collection('tasks').get();
        for(task of tasksRef.docs) {
            console.log(task.id, task.data())
        } 
    }
}

When I use (CHOICE 2) , "documentRef" is not a valid DocumentReference ERROR show.
There is no variable named documentRef in my code( as a note to those comment who wrongly think so)

I wonder why? shouldnt campaign equal campaignsRef.doc(campaign.id)?

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

0

Everything you wrote in the second election is correct, except for one thing. The variable (campaign) created in the for loop is DocumentSnapshot. You have to use .ref to access reference from DocumentSnapshot.

async function process_tasks() {
    let campaignsRef = db.collection('campaigns')
    let activeRef = await campaignsRef.where('active', '==', true).select().get();
    for (campaign of activeRef.docs) {
    //campaign is DocumentSnapshot
        console.log(campaign.id);
        (CHOICE 1) let tasksRef = await campaignsRef.doc(campaign.id).collection('tasks').get();
        (CHOICE 2) let tasksRef = await campaign.ref.collection('tasks').get(); // add .ref after campaign
        for(task of tasksRef.docs) {
            console.log(task.id, task.data())
        } 
    }
}

Thanks.

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!