Tengo un problema. Mi aplicación permite al usuario filtrar ofertas por algunos parámetros. Me gustaría obtener datos con el operador .where() cuando necesito apilarlos. ¿Cómo puedo hacerlo?
Mi intento (no funciona):
let query = db.collection("cards").where("cardId", "==", id); if (filterParams.price.from && filterParams.price.to) { query .where("price", ">=", filterParams.price.from) .where("price", "<=", filterParams.price.to); } if (filterParams.graded) { query.where("isGraded", "==", filterParams.graded); } if (filterParams.condition) { query.where("condition", "==", filterParams.condition); } query = await query.get();Los objetos de consulta son inmutables. Cada vez que llama a where devuelve un nuevo objeto de Query , que debe mantener una referencia a esa consulta.
Asi que:
let query = db.collection("cards").where("cardId", "==", id); if (filterParams.price.from && filterParams.price.to) { query = query // 👈 .where("price", ">=", filterParams.price.from) .where("price", "<=", filterParams.price.to); } if (filterParams.graded) { query = query.where("isGraded", "==", filterParams.graded); // 👈 } if (filterParams.condition) { query = query.where("condition", "==", filterParams.condition); // 👈 } query = await query.get();