Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

95
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda