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

91
Views
firestore: user Array.includes with a DocumentReference

I'm trying check if an array with DocumetReferences contains a specific ref.

That's my attempt:

const likedWorkouts = user.collection('additional').doc('liked');
const snapshot = await likedWorkouts.get();
const exists = snapshot.exists;
hasLiked = snapshot.data()?.liked?.includes(workout); // This part (workout is a DocumentReference)
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

A DocumentReference is an object and you cannot compare them directly. You can use the isEqual() method to compare the refs:

hasLiked = !!snapshot.data()?.liked?.find((likeRef) => likeRef.isEqual(workout));

// Alternatively, you can compare the paths
// likeRef.path === workout.path

The DocumentReference in the new Modular SDK doesn't not have isEqual() method but instead there is a top level function refEqual(). It can be used as follows:

import { refEqual } from "firebase/firestore";

hasLiked = !!snapshot.data()?.liked?.find((likeRef) => refEqual(likeRef, workout));

Checkout MDN for more information on objects.

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!